]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix verbatim tag handling in Doxygen bridge
authorGreg Hudson <ghudson@mit.edu>
Sat, 6 Mar 2021 07:20:28 +0000 (02:20 -0500)
committerGreg Hudson <ghudson@mit.edu>
Mon, 8 Mar 2021 23:53:14 +0000 (18:53 -0500)
Commit 281210909beef4683be3b63bc1ac1e75c2c9c7eb added handling for
verbatim tags in doxybuilder_types.py, but did not check for tail
text.  This wasn't a problem in Doxygen 1.8 because its XML output
ended paragraph tags after verbatim tags, but that isn't the case in
Doxygen 1.9.  Move the is_tail check earlier so we don't have to check
for each tag type.

Also avoid putting spaces at the beginnings and ends of lines when
joining the elements of the result list, to avoid confusing the RST
parser at the end of literal blocks.

doc/tools/doxybuilder_types.py

index 063ee4bdca1be7c32ca2ba22c9a5703e4bca8da3..6fa2f02ab00179599ebd04f7842c0475894d0283 100644 (file)
@@ -268,38 +268,36 @@ class DoxyTypes(object):
 
     def _process_paragraph_content(self, node):
 
+        def add_text(l, s):
+            # Add a space if it wouldn't be at the start or end of a line.
+            if l and not l[-1].endswith('\n') and not s.startswith('\n'):
+                l.append(' ')
+            l.append(s)
+
         result = list()
         content = node.xpath(".//text()")
         for e in content:
-            if node is e.getparent():
-                result.append(e.strip())
+            if e.is_tail or node is e.getparent():
+                add_text(result, e.strip())
             elif e.getparent().tag == 'ref':
-                if e.is_tail:
-                    result.append(e.strip())
-                elif e.strip().find('(') > 0:
-                    result.append(':c:func:`%s`' % e.strip())
+                if e.strip().find('(') > 0:
+                    add_text(result, ':c:func:`%s`' % e.strip())
                 elif e.isupper():
-                    result.append(':c:data:`%s`' % e.strip())
+                    add_text(result, ':c:data:`%s`' % e.strip())
                 else:
-                    result.append(':c:type:`%s`' % e.strip())
+                    add_text(result, ':c:type:`%s`' % e.strip())
             elif e.getparent().tag == 'emphasis':
-                if e.is_tail:
-                    result.append(e.strip())
-                else:
-                    result.append('*%s*' % e.strip())
+                add_text(result, '*%s*' % e.strip())
             elif e.getparent().tag == 'computeroutput':
-                if e.is_tail:
-                    result.append(e.strip())
-                else:
-                    result.append('*%s*' % e.strip())
-            elif  e.getparent().tag == 'defname':
-                result.append('%s, ' % e.strip())
+                add_text(result, '*%s*' % e.strip())
+            elif e.getparent().tag == 'defname':
+                add_text(result, '%s, ' % e.strip())
             elif e.getparent().tag == 'verbatim':
-                result.append('\n::\n\n')
-                result.append(textwrap.indent(e, '    ', lambda x: True))
-                result.append('\n')
+                add_text(result, '\n::\n\n')
+                add_text(result, textwrap.indent(e, '    ', lambda x: True))
+                add_text(result, '\n')
 
-        result = ' '.join(result)
+        result = ''.join(result)
 
         return result