chiark / gitweb /
documentation/doxygen: normalize spacing around inline <mcss:*> tags.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 13 Sep 2024 21:47:00 +0000 (23:47 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 14 Sep 2024 00:46:33 +0000 (02:46 +0200)
Those are \xmlonly, and Doxygen 1.12 (or anything between 1.12 and
1.8.16) seems to put one more space there, causing useless differences
in test files. Replacing those with just one space to have a consistent
output across all versions.

documentation/doxygen.py
documentation/test_doxygen/contents_custom/index.html

index 397d35634320750ff670c7050d67718d02a937b1..025dfaf4eff2c913906ddff6316bf9bc0a14c22a 100755 (executable)
@@ -1156,6 +1156,15 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
         # Adding a custom CSS class to the immediately following block/inline
         # element
         elif i.tag == '{http://mcss.mosra.cz/doxygen/}class':
+            # Doxygen may put one or more spaces before, depending on the
+            # version. Replace them with just one to have consistent output
+            # across all versions. Have to keep at least one as it's often
+            # intentional, block elements such as <mcss:div> have both the
+            # leading and trailing spaces stripped always. Sane is done for
+            # <mcss:span> below.
+            if out.parsed.endswith(' '):
+                out.parsed = out.parsed.rstrip() + ' '
+
             # Bubble up in case we are alone in a paragraph, as that's meant to
             # affect the next paragraph content.
             if len([listing for listing in element]) == 1:
@@ -1397,6 +1406,15 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
         # in _document_all_stuff(). In that case the class attribute is not
         # present.
         elif i.tag == '{http://mcss.mosra.cz/doxygen/}span':
+            # Doxygen may put one or more spaces before, depending on the
+            # version. Replace them with just one to have consistent output
+            # across all versions. Have to keep at least one as it's often
+            # intentional, block elements such as <mcss:div> have both the
+            # leading and trailing spaces stripped always. Sane is done for
+            # <mcss:class> above.
+            if out.parsed.endswith(' '):
+                out.parsed = out.parsed.rstrip() + ' '
+
             content = parse_inline_desc(state, i).strip()
             if '{http://mcss.mosra.cz/doxygen/}class' in i.attrib:
                 out.parsed += '<span class="{}">{}</span>'.format(i.attrib['{http://mcss.mosra.cz/doxygen/}class'], content)
@@ -1694,13 +1712,14 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             # is done by the caller.
             out.parsed += html.escape(i.tail.lstrip())
 
-        # Otherwise strip if requested by the caller or if this is right after
-        # a line break
+        # Otherwise strip if requested by the caller, if this is right after a
+        # line break or a <mcss:div>, or if <mcss:class> was before (which
+        # likely had a space before itself as well)
         elif i.tail:
             tail: str = html.escape(i.tail)
             if trim:
                 tail = tail.strip()
-            elif out.parsed.endswith('<br />'):
+            elif out.parsed.endswith('<br />') or i.tag in ['{http://mcss.mosra.cz/doxygen/}div', '{http://mcss.mosra.cz/doxygen/}class']:
                 tail = tail.lstrip()
             out.parsed += tail
 
index 164b229fd368b651ec88d2788e4b142bf41ccd8c..d27e67f1b9c9737b84eea10b24cc98f53098a1d8 100644 (file)
@@ -22,8 +22,8 @@
         <h1>
           My Project
         </h1>
-<div class="m-note m-dim m-text-center">This paragraph <em>is</em> rendered in a dim note, centered.</div><p>This paragraph contains a <span class="m-text m-danger"><em>red</em> text</span> in a normal text flow and then  <strong class="m-text m-em m-small">small strong italics</strong>,   <em class="m-text m-info">blue italics</em> and  <a href="https://mcss.mosra.cz" class="m-text m-big">https:/<wbr />/<wbr />mcss.mosra.cz</a> (big-ass link). A styled page ref:   <a href="math.html" class="m-label m-success">The math page</a>.</p><div class="m-button m-primary"><a href="#"><div class="m-big">A button</div> <div class="m-small"><span class="m-text m-em">with</span>  <strong class="m-text m-em">subtitle</strong></div></a></div><p>A paragraph that is not affected by the inline classes from above.</p><p class="m-text m-strong m-noindent">Bold, non-indented paragraph.</p><p class="m-text m-primary"><strong>Bold text that should not have</strong> the same class as the paragraph.</p><p>A paragraph that doesn&#x27;t have any class applied. Next, a full-width image:</p><img class="m-image m-fullwidth" src="ship-small.jpg" alt="Image" /><figure class="m-figure m-flat"><img src="ship-small.jpg" alt="Image" /><figcaption>A flat figure</figcaption></figure><p>A fullwidth table:</p><table class="m-table m-fullwidth"><thead><tr><th>Table header</th><th>Another</th></tr></thead><tbody><tr><td>Cell</td><td>Another cell</td></tr><tr><td>Next row</td><td>Last.</td></tr></tbody></table><p>An unstyled list:</p><ul class="m-unstyled"><li>First item without a dot</li><li>Second item without a dot</li></ul><aside class="m-block m-info"><h3>A info block with some paragraphs inside</h3><div><p>Hello.</p><p>This is good, finally.</p></div></aside><aside class="m-frame"><h3>Note</h3><p>A note styled as a frame.</p></aside><p>This has to be here otherwise doxygen puts the next <code>@m_class</code> call into the above note. WHAT THE HELL!!!</p><aside class="m-block m-success"><h3><a href="licenses.html#_licenses000001" class="m-doc">Third-party license info</a></h3><p>This package is licensed under MIT. All is good.</p></aside><div class="m-code-figure"><pre class="m-code"><span class="c1">// this is the code</span>
-<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The answer to the universe and everything is %d.&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="o">*</span><span class="mi">9</span><span class="p">)</span></pre><p>The answer to the universe and everything is 42.</p></div><p>A paragraph containing a footnote  <a href="#note27" class="m-footnote">27</a> reference.</p><dl class="m-footnote"><dt>27.</dt><dd><a name="note27"></a>And a styled footnote, overriding the default styling which is used for TODO pages and other xrefitems, like <a href="licenses.html" class="m-doc">Third-party license info</a>.</dd></dl>
+<div class="m-note m-dim m-text-center">This paragraph <em>is</em> rendered in a dim note, centered.</div><p>This paragraph contains a <span class="m-text m-danger"><em>red</em> text</span> in a normal text flow and then <strong class="m-text m-em m-small">small strong italics</strong>, <em class="m-text m-info">blue italics</em> and <a href="https://mcss.mosra.cz" class="m-text m-big">https:/<wbr />/<wbr />mcss.mosra.cz</a> (big-ass link). A styled page ref: <a href="math.html" class="m-label m-success">The math page</a>.</p><div class="m-button m-primary"><a href="#"><div class="m-big">A button</div><div class="m-small"><span class="m-text m-em">with</span> <strong class="m-text m-em">subtitle</strong></div></a></div><p>A paragraph that is not affected by the inline classes from above.</p><p class="m-text m-strong m-noindent">Bold, non-indented paragraph.</p><p class="m-text m-primary"><strong>Bold text that should not have</strong> the same class as the paragraph.</p><p>A paragraph that doesn&#x27;t have any class applied. Next, a full-width image:</p><img class="m-image m-fullwidth" src="ship-small.jpg" alt="Image" /><figure class="m-figure m-flat"><img src="ship-small.jpg" alt="Image" /><figcaption>A flat figure</figcaption></figure><p>A fullwidth table:</p><table class="m-table m-fullwidth"><thead><tr><th>Table header</th><th>Another</th></tr></thead><tbody><tr><td>Cell</td><td>Another cell</td></tr><tr><td>Next row</td><td>Last.</td></tr></tbody></table><p>An unstyled list:</p><ul class="m-unstyled"><li>First item without a dot</li><li>Second item without a dot</li></ul><aside class="m-block m-info"><h3>A info block with some paragraphs inside</h3><div><p>Hello.</p><p>This is good, finally.</p></div></aside><aside class="m-frame"><h3>Note</h3><p>A note styled as a frame.</p></aside><p>This has to be here otherwise doxygen puts the next <code>@m_class</code> call into the above note. WHAT THE HELL!!!</p><aside class="m-block m-success"><h3><a href="licenses.html#_licenses000001" class="m-doc">Third-party license info</a></h3><p>This package is licensed under MIT. All is good.</p></aside><div class="m-code-figure"><pre class="m-code"><span class="c1">// this is the code</span>
+<span class="n">printf</span><span class="p">(</span><span class="s">&quot;The answer to the universe and everything is %d.&quot;</span><span class="p">,</span> <span class="mi">5</span><span class="o">*</span><span class="mi">9</span><span class="p">)</span></pre><p>The answer to the universe and everything is 42.</p></div><p>A paragraph containing a footnote <a href="#note27" class="m-footnote">27</a> reference.</p><dl class="m-footnote"><dt>27.</dt><dd><a name="note27"></a>And a styled footnote, overriding the default styling which is used for TODO pages and other xrefitems, like <a href="licenses.html" class="m-doc">Third-party license info</a>.</dd></dl>
       </div>
     </div>
   </div>