chiark / gitweb /
doxygen: improve heuristics for inline code.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 6 Dec 2017 13:10:28 +0000 (14:10 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 7 Dec 2017 01:23:41 +0000 (02:23 +0100)
Now it should be finally robust. The test passes again.

doc/doxygen.rst
doxygen/dox2html5.py

index 7af90e00ae3e5108709db475c77dd9bc632052d9..d8f5f5309d4de551144414db49c0dca90c7c9b20 100644 (file)
@@ -379,7 +379,10 @@ distinguished from code blocks using the following rules:
 
 -   Code that is delimited from surrounding paragraphs with an empty line is
     considered as block.
--   Code that is not alone in a paragraph is considered as inline.
+-   Code that is coming from ``@include``, ``@snippet`` and related commands
+    that paste external file content is always considered as block.
+-   Code that is coming from ``@code`` and is not alone in a paragraph is
+    considered as inline.
 -   For compatibility reasons, if code that is detected as inline consists of
     more than one line, it's rendered as code block and a warning is printed to
     output.
@@ -424,26 +427,9 @@ aliases in the original ``Doxyfile``:
 
 .. block-warning:: Doxygen limitations
 
-    Due to Doxygen limitations, sometimes a single-line code block coming from
-    ``@skipline`` and related commands is detected as inline code and prepended
-    to the immediately following paragraph. In order to prevent that, add a
-    stray :html:`<p>` tag right
-    after the block:
-
-    .. code:: c++
-
-        /**
-        Text paragraph before a code block.
-
-        @skipline foo
-        <p>
-
-        Next text paragraph after a code block.
-        */
-
-    Besides that, it's not possible to use inline code highlighting in
-    ``@brief`` description. Code placed there is moved by Doxygen to the
-    detailed description.
+    It's not possible to use inline code highlighting in ``@brief``
+    description. Code placed there is moved by Doxygen to the detailed
+    description.
 
 .. block-warning:: Doxygen patches
 
index 98f6998c0df873c527d4d48a2d734231f96153ea..464a951d4d4e5f1c996a70f0c315fa4910ab79e3 100755 (executable)
@@ -319,8 +319,14 @@ def parse_desc_internal(state: State, element: ET.Element, trim = True):
 
         elif i.tag == 'programlisting':
             # Seems to be a standalone code paragraph, don't wrap it in <p>
-            # and use <pre>
-            if element.tag == 'para' and (not element.text or not element.text.strip()) and (not i.tail or not i.tail.strip()) and len([listing for listing in element]) == 1:
+            # and use <pre>:
+            # - is either alone in the paragraph, with no text or other
+            #   elements around
+            # - or is a code snippet (filename instead of just .ext). Doxygen
+            #   unfortunately doesn't put @snippet in its own paragraph even
+            #   if it's separated by blank lines. It does so for @include and
+            #   related, though.
+            if element.tag == 'para' and (((not element.text or not element.text.strip()) and (not i.tail or not i.tail.strip()) and len([listing for listing in element]) == 1) or ('filename' in i.attrib and not i.attrib['filename'].startswith('.'))):
                 code_block = True
 
             # Looks like inline code, but has multiple code lines, so it's
@@ -336,7 +342,6 @@ def parse_desc_internal(state: State, element: ET.Element, trim = True):
                 # Doxygen doesn't add a space before <programlisting> if it's
                 # inline, add it manually in case there should be a space
                 # before it. However, it does add a space after it always.
-                # TODO: could this be used to detect the problematic case?
                 if out.parsed and not out.parsed[-1].isspace() and not out.parsed[-1] in '([{':
                     out.parsed += ' '