[gtk-doc] mkdb: strip leading indentation from param docs.



commit 5e6571179cbd9f6deda565821cddf1fda1ebcc2c
Author: Stefan Sauer <ensonic users sf net>
Date:   Tue Apr 9 19:22:09 2019 +0200

    mkdb: strip leading indentation from param docs.
    
    This fixes the cases using markdown lists in parameter docs.
    See #76

 gtkdoc/mkdb.py | 16 ++++++++++++++++
 tests/mkdb.py  | 12 ++++++++++++
 2 files changed, 28 insertions(+)
---
diff --git a/gtkdoc/mkdb.py b/gtkdoc/mkdb.py
index 9652276..fb6ce7f 100644
--- a/gtkdoc/mkdb.py
+++ b/gtkdoc/mkdb.py
@@ -3773,6 +3773,7 @@ def SegmentCommentBlock(lines, line_number=0, ifile=''):
     segments = {'body': ''}
     params = OrderedDict()
     param_name = None
+    param_indent = None
     line_number -= 1
     for line in lines:
         line_number += 1
@@ -3840,6 +3841,7 @@ def SegmentCommentBlock(lines, line_number=0, ifile=''):
         if m:
             param_name = m.group(1)
             param_desc = line[m.end():]
+            param_indent = None
 
             # Allow varargs variations
             if re.search(r'^\.\.\.$', param_name):
@@ -3864,6 +3866,20 @@ def SegmentCommentBlock(lines, line_number=0, ifile=''):
             common.LogWarning(ifile, line_number,
                               "Parsing comment block file : parameter expected, but got '%s'" % line)
         else:
+            if not param_indent:
+                # determine indentation of first continuation line
+                spc = len(line) - len(line.lstrip(' '))
+                if spc > 0:
+                    param_indent = spc
+                    logging.debug("Found param-indentation of %d", param_indent)
+            if param_indent:
+                # cut common indentation (after double checking that it is all spaces)
+                if line[:param_indent].strip() == '':
+                    line = line[param_indent:]
+                else:
+                    logging.warning("Not cutting param-indentation for %s: '%s'",
+                                    param_name, line[:param_indent])
+
             params[param_name] += line
 
     return (symbol, segments, params)
diff --git a/tests/mkdb.py b/tests/mkdb.py
index 9af1803..9d58c77 100755
--- a/tests/mkdb.py
+++ b/tests/mkdb.py
@@ -77,6 +77,18 @@ class ParseCommentBlock(ScanSourceContentTestCase):
         self.assertIn('symbol', mkdb.SourceSymbolParams)
         self.assertEqual({'par': 'value\n'}, mkdb.SourceSymbolParams['symbol'])
 
+    def test_FindsDocCommentWithMultilineParam(self):
+        mkdb.ParseCommentBlock(textwrap.dedent("""\
+             symbol:
+             @par: value docs with
+               two lines
+
+             Description.
+             """).splitlines(keepends=True))
+        self.assertEqual({'symbol': 'Description.\n'}, mkdb.SourceSymbolDocs)
+        self.assertIn('symbol', mkdb.SourceSymbolParams)
+        self.assertEqual({'par': 'value docs with\ntwo lines\n'}, mkdb.SourceSymbolParams['symbol'])
+
     def test_FindsDocCommentWithReturns(self):
         mkdb.ParseCommentBlock(textwrap.dedent("""\
              symbol:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]