[gobject-introspection/gir-docbook] scanner: Don't throw away blank lines in the docs



commit 1037bdc150df91abdc7c7f4e8bb278fe7e4b5cee
Author: Colin Walters <walters verbum org>
Date:   Fri Aug 12 06:01:56 2011 -0400

    scanner: Don't throw away blank lines in the docs
    
    For generating documentation, we actually want to preserve these.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656389

 giscanner/annotationparser.py          |   13 ++++++++++---
 giscanner/girparser.py                 |    3 ++-
 giscanner/girwriter.py                 |    2 +-
 tests/scanner/Regress-1.0-expected.gir |   13 +++++++++++++
 tests/scanner/regress.c                |   16 ++++++++++++++++
 tests/scanner/regress.h                |    2 ++
 6 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index ac6430d..0d7672e 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -492,13 +492,20 @@ class AnnotationParser(object):
         lineno = 2
         for line in comment[pos+1:].split('\n'):
             line = line.lstrip()
-            if (not line.startswith('*') or
-                self.WHITESPACE_RE.match(line[1:])):
+            if not line.startswith('*'):
+                lineno += 1
+                continue
+            is_whitespace = self.WHITESPACE_RE.match(line[1:]) is not None
+            if parsing_parameters and is_whitespace:
                 # As soon as we find a line that's just whitespace,
                 # we're done parsing the parameters.
                 parsing_parameters = False
                 lineno += 1
                 continue
+            elif is_whitespace:
+                comment_lines.append('')
+                lineno += 1
+                continue
 
             line = line[1:].lstrip()
 
@@ -576,7 +583,7 @@ class AnnotationParser(object):
             elif (not is_parameter):
                 comment_lines.append(line)
             lineno += 1
-        block.comment = '\n'.join(comment_lines)
+        block.comment = '\n'.join(comment_lines).strip()
         block.validate()
         self._blocks[block.name] = block
 
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 45a93ed..51de1b1 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -199,7 +199,8 @@ class GIRParser(object):
             return
         doc = node.find(_corens('doc'))
         if doc is not None:
-            obj.doc = doc.text
+            if doc.text:
+                obj.doc = doc.text
         version = node.attrib.get('version')
         if version:
             obj.version = version
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 1da2417..b3b7435 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -135,7 +135,7 @@ and/or use gtk-doc annotations. ''')
             self.write_tag('attribute', [('name', key), ('value', value)])
         if hasattr(node, 'doc') and node.doc:
             self.write_tag('doc', [('xml:whitespace', 'preserve')],
-                           node.doc.strip())
+                           node.doc)
 
     def _append_node_generic(self, node, attrs):
         if node.skip or not node.introspectable:
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index a19969e..7e0b2e5 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -2342,6 +2342,19 @@ call and can be released on return.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="test_multiline_doc_comments"
+              c:identifier="regress_test_multiline_doc_comments">
+      <doc xml:whitespace="preserve">This is a function.
+
+It has multiple lines in the documentation.
+
+The sky is blue.
+
+You will give me your credit card number.</doc>
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+    </function>
     <function name="test_short" c:identifier="regress_test_short">
       <return-value transfer-ownership="none">
         <type name="gshort" c:type="gshort"/>
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index c6608f4..86927a0 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -3143,6 +3143,22 @@ regress_test_strv_in_gvalue (void)
 }
 
 /**
+ * regress_test_multiline_doc_comments:
+ *
+ * This is a function.
+ *
+ * It has multiple lines in the documentation.
+ *
+ * The sky is blue.
+ *
+ * You will give me your credit card number.
+ */
+void
+regress_test_multiline_doc_comments (void)
+{
+}
+
+/**
  * regress_introspectable_via_alias:
  *
  */
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 04ebe29..7b8d9de 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -608,6 +608,8 @@ GValue *regress_test_strv_in_gvalue (void);
 
 GObject * _regress_this_is_a_private_symbol (void);
 
+void regress_test_multiline_doc_comments (void);
+
 /**
  * RegressSkippedStructure: (skip)
  *



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