chiark / gitweb /
doxygen: make it possible to override styling of all blocks.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 16 Nov 2018 21:13:51 +0000 (22:13 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 16 Nov 2018 23:29:39 +0000 (00:29 +0100)
Finally I can have custom xrefitems.

doc/doxygen.rst
doxygen/dox2html5.py
doxygen/test/contents_blocks/index.html
doxygen/test/contents_blocks/input.dox
doxygen/test/contents_custom/index.html
doxygen/test/contents_custom/input.dox

index f25dcfb0e3b221ef74fcbbc36023ed61d31436fb..fe5d687e074043e761b39bdceaa2f4c7215ec82b 100644 (file)
@@ -818,9 +818,33 @@ aliases however you want to fit your naming scheme.
         "m_enum_values_as_keywords="
 
 With ``@m_class`` it's possible to add CSS classes to the immediately following
-paragraph, image, table, list or math formula block. When used inline, it
-affects the immediately following emphasis, strong text, link or inline math
-formula. Example usage:
+paragraph, image, table, list or math formula block. When used before a block
+such as ``@par``, ``@note``, ``@see`` or ``@xrefitem``, the CSS class fully
+overrides the block styling. By default :css:`.m-note` with some color and
+:html:`<h4>` is used, with ``@m_class`` before it get :html:`<h3>` for the
+title and you can turn it into a block, for example:
+
+.. code-figure::
+
+    .. code:: c++
+
+        /**
+        @m_class{m-block m-success}
+
+        @par Third-party license info
+            This utility depends on the [Magnum engine](https://magnum.graphics).
+            It's licensed under MIT, so all you need to do is mention it in the
+            credits of your commercial app.
+        */
+
+    .. block-success:: Third-party license info
+
+        This utility depends on the `Magnum engine <https://magnum.graphics>`_.
+        It's licensed under MIT, so all you need to do is mention it in the
+        credits of your commercial app.
+
+When used inline, it affects the immediately following emphasis, strong text,
+link or inline math formula. Example usage:
 
 .. code-figure::
 
index 8b4b32151d0e218af743e9f7354e688313d020a4..a6f35ec3d8e63af5d78afbc595e27dac25fadfba 100755 (executable)
@@ -921,44 +921,73 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
                 # Not continuing with a section from before, put a header in
                 if not previous_section or (i.attrib['kind'] != 'par' and previous_section != i.attrib['kind']) or (i.attrib['kind'] == 'par' and i.find('title').text):
                     if i.attrib['kind'] == 'see':
-                        out.parsed += '<aside class="m-note m-default"><h4>See also</h4>'
+                        title = 'See also'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'note':
-                        out.parsed += '<aside class="m-note m-info"><h4>Note</h4>'
+                        title = 'Note'
+                        css_class = 'm-info'
                     elif i.attrib['kind'] == 'attention':
-                        out.parsed += '<aside class="m-note m-warning"><h4>Attention</h4>'
+                        title = 'Attention'
+                        css_class = 'm-warning'
                     elif i.attrib['kind'] == 'warning':
-                        out.parsed += '<aside class="m-note m-danger"><h4>Warning</h4>'
+                        title = 'Warning'
+                        css_class = 'm-danger'
                     elif i.attrib['kind'] == 'author':
-                        out.parsed += '<aside class="m-note m-default"><h4>Author</h4>'
+                        title = 'Author'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'authors':
-                        out.parsed += '<aside class="m-note m-default"><h4>Authors</h4>'
+                        title = 'Authors'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'copyright':
-                        out.parsed += '<aside class="m-note m-default"><h4>Copyright</h4>'
+                        title = 'Copyright'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'version':
-                        out.parsed += '<aside class="m-note m-default"><h4>Version</h4>'
+                        title = 'Version'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'since':
-                        out.parsed += '<aside class="m-note m-default"><h4>Since</h4>'
+                        title = 'Since'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'date':
-                        out.parsed += '<aside class="m-note m-default"><h4>Date</h4>'
+                        title = 'Date'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'pre':
-                        out.parsed += '<aside class="m-note m-success"><h4>Precondition</h4>'
+                        title = 'Precondition'
+                        css_class = 'm-success'
                     elif i.attrib['kind'] == 'post':
-                        out.parsed += '<aside class="m-note m-success"><h4>Postcondition</h4>'
+                        title = 'Postcondition'
+                        css_class = 'm-success'
                     elif i.attrib['kind'] == 'invariant':
-                        out.parsed += '<aside class="m-note m-success"><h4>Invariant</h4>'
+                        title = 'Invariant'
+                        css_class = 'm-success'
                     elif i.attrib['kind'] == 'remark':
-                        out.parsed += '<aside class="m-note m-default"><h4>Remark</h4>'
+                        title = 'Remark'
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'par':
-                        if add_css_class:
-                            out.parsed += '<aside class="{}"><h3>{}</h3>'.format(add_css_class, html.escape(i.findtext('title', '')))
-                        else:
-                            out.parsed += '<aside class="m-note m-default"><h4>{}</h4>'.format(html.escape(i.findtext('title', '')))
+                        title = html.escape(i.findtext('title', ''))
+                        css_class = 'm-default'
                     elif i.attrib['kind'] == 'rcs':
-                        out.parsed += '<aside class="m-note m-default"><h4>{}</h4>'.format(html.escape(i.findtext('title', '')))
+                        title = html.escape(i.findtext('title', ''))
+                        css_class = 'm-default'
                     else: # pragma: no cover
-                        out.parsed += '<aside class="m-note">'
+                        title = ''
+                        css_class = ''
                         logging.warning("{}: ignoring {} kind of <simplesect>".format(state.current, i.attrib['kind']))
 
+                    if add_css_class:
+                        css_class = add_css_class
+                        heading = 'h3'
+                    else:
+                        css_class = 'm-note ' + css_class
+                        heading = 'h4'
+
+                    if title:
+                        out.parsed += '<aside class="{css_class}"><{heading}>{title}</{heading}>'.format(
+                            css_class=css_class,
+                            heading=heading,
+                            title=title)
+                    else:
+                        out.parsed += '<aside class="{}">'.format(css_class)
+
                 # Parse the section contents and bubble important stuff up
                 parsed, search_keywords, search_enum_values_as_keywords = parse_desc_keywords(state, i)
                 out.parsed += parsed
@@ -987,17 +1016,28 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             id = i.attrib['id']
             match = xref_id_rx.match(id)
             file = match.group(1)
-            if file.startswith('deprecated'):
-                color = 'm-danger'
-                out.is_deprecated = True
-            elif file.startswith('bug'):
-                color = 'm-danger'
-            elif file.startswith('todo'):
-                color = 'm-dim'
+            if add_css_class:
+                css_class = add_css_class
+                heading = 'h3'
             else:
-                color = 'm-default'
-            out.parsed += '<aside class="m-note {}"><h4><a href="{}.html#{}" class="m-dox">{}</a></h4>{}</aside>'.format(
-                color, file, match.group(2), i.find('xreftitle').text, parse_desc(state, i.find('xrefdescription')))
+                heading = 'h4'
+                css_class = 'm-note '
+                if file.startswith('deprecated'):
+                    css_class += 'm-danger'
+                    out.is_deprecated = True
+                elif file.startswith('bug'):
+                    css_class += 'm-danger'
+                elif file.startswith('todo'):
+                    css_class += 'm-dim'
+                else:
+                    css_class += 'm-default'
+            out.parsed += '<aside class="{css_class}"><{heading}><a href="{file}.html#{anchor}" class="m-dox">{title}</a></{heading}>{description}</aside>'.format(
+                css_class=css_class,
+                heading=heading,
+                file=file,
+                anchor=match.group(2),
+                title=i.find('xreftitle').text,
+                description=parse_desc(state, i.find('xrefdescription')))
 
         elif i.tag == 'parameterlist':
             assert element.tag == 'para' # is inside a paragraph :/
index da4fd88b0f577f0ced57a158dad75abc799ac7e4..407b6d5f496ef9d842ee8c1cc9d4e54dc622f3ad 100644 (file)
@@ -22,7 +22,7 @@
         <h1>
           My Project
         </h1>
-<p>First paragraph containing some content.</p><aside class="m-note m-warning"><h4>Attention</h4><p>An attention section.</p></aside><aside class="m-note m-default"><h4>See also</h4><p>Other section.</p></aside><p>Paragraph following the sections.</p><aside class="m-note m-info"><h4>Note</h4><p>A note.</p></aside><aside class="m-note m-danger"><h4><a href="bug.html#_bug000001" class="m-dox">Bug</a></h4><p>This is a bug.</p></aside><aside class="m-note m-dim"><h4><a href="todo.html#_todo000001" class="m-dox">Todo</a></h4><p>Or a TODO.</p></aside><aside class="m-note m-danger"><h4><a href="deprecated.html#_deprecated000001" class="m-dox">Deprecated</a></h4><p>Which is deprecated.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000001" class="m-dox">Old stuff</a></h4><p>This is old.</p></aside><blockquote><p>A blockquote</p></blockquote><p>Text right after that blockquote should be a new paragraph.</p><ul><li>A simple</li><li>List<ol><li>With one line</li><li>for each</li></ol></li><li>item, so paragraphs are removed</li></ul><ul><li>A simple</li><li>List<ol><li>With the sublist delimited</li><li>by blank lines</li></ol></li><li>should behave the same as above</li></ul><ul><li><p>A new list</p><p>of multiple</p><p>paragraphs.</p></li><li><p>Another item</p><ul><li><p>A sub list</p><p>Another paragraph</p></li></ul></li></ul><p>A paragraph after that list.</p><table class="m-table"><thead><tr><th>Table header</th><th>Another</th><th>Third</th></tr></thead><tbody><tr><td>Cell</td><td>Another cell</td><td>3rd</td></tr><tr><td>Next row</td><td></td><td>This</td></tr><tr><td>is a table</td><td><em>really</em></td><td>yes.</td></tr></tbody></table><table class="m-table"><caption>Table <em>caption</em></caption><thead><tr><th>Table</th><th>with</th></tr><tr><th>two</th><th>row</th></tr></thead><tbody><tr><td>table</td><td>header</td></tr></tbody></table><aside class="m-note m-warning"><h4>Attention</h4><p>Attention, first paragraph.</p><p>Attention, second paragraph.</p><p>Attention, third paragraph.</p></aside><aside class="m-note m-info"><h4>Note</h4><p>A note, not merged with the above.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000002" class="m-dox">Old stuff</a></h4><p>This is not merged.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000003" class="m-dox">Old stuff</a></h4><p>With this. Only on the listing page.</p></aside><aside class="m-note m-danger"><h4>Warning</h4><p>Non-text item after a note/whatever should be part of a paragraph:</p></aside><p><em>This is</em> inside a paragraph.</p><aside class="m-note m-default"><h4>Id</h4><p>some strange RCS content</p></aside><aside class="m-note m-default"><h4>Author</h4><p>The Author</p></aside><aside class="m-note m-default"><h4>Authors</h4><p>Another Author, That Intern We Forgot The Name Of</p></aside><aside class="m-note m-default"><h4>Version</h4><p>1.0rc3</p></aside><aside class="m-note m-default"><h4>Since</h4><p>1.0rc1</p></aside><aside class="m-note m-default"><h4>Date</h4><p>2018-02-09</p></aside><aside class="m-note m-success"><h4>Precondition</h4><p>A precondition.</p></aside><aside class="m-note m-success"><h4>Postcondition</h4><p>A postcondition.</p></aside><aside class="m-note m-default"><h4>Copyright</h4><p>This is illegal to use.</p></aside><aside class="m-note m-success"><h4>Invariant</h4><p>Everything is changing all the time.</p></aside><aside class="m-note m-default"><h4>Remark</h4><p>What does a <code>remark</code> mean and how is it different from <code>note</code>, anyway?</p><p>Paragraph that goes to the remark section</p></aside><aside class="m-note m-default"><h4>Paragraph title</h4><p>Paragraph that goes separately</p><p>Paragraph that adds to the previous</p></aside><aside class="m-note m-default"><h4>Block title</h4><div><p>Hello!</p><p>Here is something inside that paragraph block.</p></div></aside>
+<p>First paragraph containing some content.</p><aside class="m-note m-warning"><h4>Attention</h4><p>An attention section.</p></aside><aside class="m-note m-default"><h4>See also</h4><p>Other section.</p></aside><p>Paragraph following the sections.</p><aside class="m-note m-info"><h4>Note</h4><p>A note.</p></aside><aside class="m-note m-danger"><h4><a href="bug.html#_bug000001" class="m-dox">Bug</a></h4><p>This is a bug.</p></aside><aside class="m-note m-dim"><h4><a href="todo.html#_todo000001" class="m-dox">Todo</a></h4><p>Or a TODO.</p></aside><aside class="m-note m-danger"><h4><a href="deprecated.html#_deprecated000001" class="m-dox">Deprecated</a></h4><p>Which is deprecated.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000001" class="m-dox">Old stuff</a></h4><p>This is old.</p></aside><blockquote><p>A blockquote</p></blockquote><p>Text right after that blockquote should be a new paragraph.</p><ul><li>A simple</li><li>List<ol><li>With one line</li><li>for each</li></ol></li><li>item, so paragraphs are removed</li></ul><ul><li>A simple</li><li>List<ol><li>With the sublist delimited</li><li>by blank lines</li></ol></li><li>should behave the same as above</li></ul><ul><li><p>A new list</p><p>of multiple</p><p>paragraphs.</p></li><li><p>Another item</p><ul><li><p>A sub list</p><p>Another paragraph</p></li></ul></li></ul><p>A paragraph after that list.</p><table class="m-table"><thead><tr><th>Table header</th><th>Another</th><th>Third</th></tr></thead><tbody><tr><td>Cell</td><td>Another cell</td><td>3rd</td></tr><tr><td>Next row</td><td></td><td>This</td></tr><tr><td>is a table</td><td><em>really</em></td><td>yes.</td></tr></tbody></table><table class="m-table"><caption>Table <em>caption</em></caption><thead><tr><th>Table</th><th>with</th></tr><tr><th>two</th><th>row</th></tr></thead><tbody><tr><td>table</td><td>header</td></tr></tbody></table><aside class="m-note m-default"><p>A paragraph with no title.</p></aside><aside class="m-note m-warning"><h4>Attention</h4><p>Attention, first paragraph.</p><p>Attention, second paragraph.</p><p>Attention, third paragraph.</p></aside><aside class="m-note m-info"><h4>Note</h4><p>A note, not merged with the above.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000002" class="m-dox">Old stuff</a></h4><p>This is not merged.</p></aside><aside class="m-note m-default"><h4><a href="old.html#_old000003" class="m-dox">Old stuff</a></h4><p>With this. Only on the listing page.</p></aside><aside class="m-note m-danger"><h4>Warning</h4><p>Non-text item after a note/whatever should be part of a paragraph:</p></aside><p><em>This is</em> inside a paragraph.</p><aside class="m-note m-default"><h4>Id</h4><p>some strange RCS content</p></aside><aside class="m-note m-default"><h4>Author</h4><p>The Author</p></aside><aside class="m-note m-default"><h4>Authors</h4><p>Another Author, That Intern We Forgot The Name Of</p></aside><aside class="m-note m-default"><h4>Version</h4><p>1.0rc3</p></aside><aside class="m-note m-default"><h4>Since</h4><p>1.0rc1</p></aside><aside class="m-note m-default"><h4>Date</h4><p>2018-02-09</p></aside><aside class="m-note m-success"><h4>Precondition</h4><p>A precondition.</p></aside><aside class="m-note m-success"><h4>Postcondition</h4><p>A postcondition.</p></aside><aside class="m-note m-default"><h4>Copyright</h4><p>This is illegal to use.</p></aside><aside class="m-note m-success"><h4>Invariant</h4><p>Everything is changing all the time.</p></aside><aside class="m-note m-default"><h4>Remark</h4><p>What does a <code>remark</code> mean and how is it different from <code>note</code>, anyway?</p><p>Paragraph that goes to the remark section</p></aside><aside class="m-note m-default"><h4>Paragraph title</h4><p>Paragraph that goes separately</p><p>Paragraph that adds to the previous</p></aside><aside class="m-note m-default"><h4>Block title</h4><div><p>Hello!</p><p>Here is something inside that paragraph block.</p></div></aside>
       </div>
     </div>
   </div>
index 73440f5e4c0f91488aedb394e0928acc00f78319..73353f1fb7596b1833022fd95554453370437058 100644 (file)
@@ -75,6 +75,9 @@ is a table      | *really*      | yes.
   </tr>
 </table>
 
+@par
+    A paragraph with no title.
+
 @attention
     Attention, first paragraph.
 @attention
index 251a84ee2eefa7ba2f68d3433ba08f330855c833..b993de9fd2a7016612acbf5017fd2e03bd1e65b0 100644 (file)
@@ -22,7 +22,7 @@
         <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).</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><div class="m-code-figure"><pre class="m-code"><span class="c1">// this is the code</span>
+<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).</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-dox">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>
       </div>
     </div>
index e52258c44695b065526642b94ffeea181c10f55b..d0fcc30ef6bf47ec777edd167aa04070fc9f529e 100644 (file)
@@ -55,6 +55,18 @@ Hello.
 This is good, finally.
 @endparblock
 
+@m_class{m-frame}
+
+@note A note styled as a frame.
+
+This has to be here otherwise doxygen puts the next `@m_class` call into the
+above note. WHAT THE HELL!!!
+
+@m_class{m-block m-success}
+
+@xrefitem licenses "Third-party license info" "Third-party license info"
+    This package is licensed under MIT. All is good.
+
 @m_class{m-code-figure}
 
 @parblock