[glib/ebassi/gdbus-codegen-rst: 2/7] codegen: Do not add extra paragraph elements while parsing




commit 5013d0831517b77bd53ad6b770eee81eac03f5f2
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jan 20 15:15:49 2022 +0000

    codegen: Do not add extra paragraph elements while parsing
    
    When parsing a comment we're adding <para> elements ourselves, but the
    DocBook generator already wraps any block of text that does not start
    with a <para> element with one.

 gio/gdbus-2.0/codegen/codegen_docbook.py | 12 ++++++++++--
 gio/gdbus-2.0/codegen/parser.py          | 13 ++++++-------
 2 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/codegen_docbook.py b/gio/gdbus-2.0/codegen/codegen_docbook.py
index 4b69e2927..b8d683408 100644
--- a/gio/gdbus-2.0/codegen/codegen_docbook.py
+++ b/gio/gdbus-2.0/codegen/codegen_docbook.py
@@ -345,9 +345,17 @@ class DocbookCodeGenerator:
 
     def expand_paras(self, s, expandParamsAndConstants):
         s = self.expand(s, expandParamsAndConstants).strip()
+        res = []
         if not s.startswith("<para"):
-            s = "<para>%s</para>" % s
-        return s
+            res.append("<para>")
+        for line in s.split("\n"):
+            line = line.strip()
+            if not line:
+                line = "</para><para>"
+            res.append(line)
+        if not s.endswith("</para>"):
+            res.append("</para>")
+        return "\n".join(res)
 
     def generate_expand_dicts(self):
         self.expand_member_dict = {}
diff --git a/gio/gdbus-2.0/codegen/parser.py b/gio/gdbus-2.0/codegen/parser.py
index 45226d540..cf8ea5229 100644
--- a/gio/gdbus-2.0/codegen/parser.py
+++ b/gio/gdbus-2.0/codegen/parser.py
@@ -85,7 +85,7 @@ class DBusXMLParser:
                         symbol = line[0:colon_index]
                         rest_of_line = line[colon_index + 2 :].strip()
                         if len(rest_of_line) > 0:
-                            body += "<para>" + rest_of_line + "</para>"
+                            body += f"{rest_of_line}\n"
                         comment_state = DBusXMLParser.COMMENT_STATE_PARAMS
             elif comment_state == DBusXMLParser.COMMENT_STATE_PARAMS:
                 if line.startswith("@"):
@@ -93,9 +93,9 @@ class DBusXMLParser:
                     if colon_index == -1:
                         comment_state = DBusXMLParser.COMMENT_STATE_BODY
                         if not in_para:
-                            body += "<para>"
+                            body += "\n"
                             in_para = True
-                        body += orig_line + "\n"
+                        body += f"{orig_line}\n"
                     else:
                         param = line[1:colon_index]
                         docs = line[colon_index + 2 :]
@@ -104,21 +104,20 @@ class DBusXMLParser:
                     comment_state = DBusXMLParser.COMMENT_STATE_BODY
                     if len(line) > 0:
                         if not in_para:
-                            body += "<para>"
+                            body += "\n"
                             in_para = True
                         body += orig_line + "\n"
             elif comment_state == DBusXMLParser.COMMENT_STATE_BODY:
                 if len(line) > 0:
                     if not in_para:
-                        body += "<para>"
                         in_para = True
                     body += orig_line + "\n"
                 else:
                     if in_para:
-                        body += "</para>"
+                        body += "\n"
                         in_para = False
         if in_para:
-            body += "</para>"
+            body += "\n"
 
         if symbol != "":
             self.doc_comment_last_symbol = symbol


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