chiark / gitweb /
doxygen: table parsing.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 6 Dec 2017 21:48:37 +0000 (22:48 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 7 Dec 2017 01:23:41 +0000 (02:23 +0100)
doc/doxygen.rst
doxygen/dox2html5.py
doxygen/test/contents_blocks/index.html
doxygen/test/contents_blocks/input.dox

index f2379c1afd4a74f19b7172086eb08dcdc6e85ef0..0696f9e7b939a6973b6fb0fa937517da50f48105 100644 (file)
@@ -306,13 +306,13 @@ modifications:
     added after ``::`` and ``_`` in long symbols in link titles and after ``/``
     in URLs.
 
-Single-paragraph list items, function parameter description and return value
-documentation is stripped from the enclosing :html:`<p>` tag to make the output
-more compact. If multiple paragraphs are present, nothing is stripped. In case
-of lists, they are then rendered in an inflated form. However, in order to
-achieve even spacing also with single-paragraph items, it's needed use some
-explicit markup. Adding :html:`<p></p>` to a single-paragraph item will make
-sure the enclosing :html:`<p>` is not stripped.
+Single-paragraph list items, function parameter description, table cell content
+and return value documentation is stripped from the enclosing :html:`<p>` tag
+to make the output more compact. If multiple paragraphs are present, nothing is
+stripped. In case of lists, they are then rendered in an inflated form.
+However, in order to achieve even spacing also with single-paragraph items,
+it's needed use some explicit markup. Adding :html:`<p></p>` to a
+single-paragraph item will make sure the enclosing :html:`<p>` is not stripped.
 
 .. code-figure::
 
index 28c66b0bdee58111200cfc567714b0556ed039cb..6f594258d614e0e390c8b55140ae333fe3c41803 100755 (executable)
@@ -180,7 +180,7 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
         # - <simplesect> and <xrefsect>
         # - <verbatim>
         # - <variablelist>, <itemizedlist>, <orderedlist>
-        # - <image>
+        # - <image>, <table>
         # - block <formula>
         # - <programlisting> (complex block/inline autodetection involved, so
         #   the check is deferred to later in the loop)
@@ -198,7 +198,7 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
         # I.e., not wrapping "A paragraph" in a <p>, but only if it's
         # immediately followed by another and it's the first paragraph in a
         # list item. We check that using the immediate_parent variable.
-        if (i.tag in ['heading', 'blockquote', 'xrefsect', 'variablelist', 'verbatim', 'itemizedlist', 'orderedlist', 'image'] or (i.tag == 'simplesect' and i.attrib['kind'] != 'return') or (i.tag == 'formula' and i.text.startswith('\[ ') and i.text.endswith(' \]'))) and element.tag == 'para' and out.write_paragraph_close_tag:
+        if (i.tag in ['heading', 'blockquote', 'xrefsect', 'variablelist', 'verbatim', 'itemizedlist', 'orderedlist', 'image', 'table'] or (i.tag == 'simplesect' and i.attrib['kind'] != 'return') or (i.tag == 'formula' and i.text.startswith('\[ ') and i.text.endswith(' \]'))) and element.tag == 'para' and out.write_paragraph_close_tag:
             out.is_reasonable_paragraph = False
             out.parsed = out.parsed.rstrip()
             if not out.parsed:
@@ -311,6 +311,31 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
                 out.parsed += '<li>{}</li>'.format(parse_desc(state, li))
             out.parsed += '</{}>'.format(tag)
 
+        elif i.tag == 'table':
+            has_block_elements = True
+            out.parsed += '<table class="m-table">'
+            inside_tbody = False
+
+            row: ET.Element
+            for row in i:
+                assert row.tag == 'row'
+                is_header_row = True
+                row_data = ''
+                for entry in row:
+                    assert entry.tag == 'entry'
+                    is_header = entry.attrib['thead'] == 'yes'
+                    is_header_row = is_header_row and is_header
+                    row_data += '<{0}>{1}</{0}>'.format('th' if is_header else 'td', parse_desc(state, entry))
+                if is_header_row:
+                    assert not inside_tbody # Assume there's only one header row
+                    out.parsed += '<thead><tr>{}</tr></thead><tbody>'.format(row_data)
+                    inside_tbody = True
+                else:
+                    out.parsed += '<tr>{}</tr>'.format(row_data)
+
+            if inside_tbody: out.parsed += '</tbody>'
+            out.parsed += '</table>'
+
         elif i.tag == 'simplesect':
             # Return value is separated from the text flow
             if i.attrib['kind'] == 'return':
@@ -601,8 +626,9 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             out.parsed = out.parsed[3:-4]
 
     # Strip superfluous <p> for simple elments (list items, parameter and
-    # return value description), but only if there is just a single paragraph
-    elif (element.tag in ['listitem', 'parameterdescription'] or (element.tag == 'simplesect' and element.attrib['kind'] == 'return')) and not has_block_elements and paragraph_count == 1:
+    # return value description, table cells), but only if there is just a
+    # single paragraph
+    elif (element.tag in ['listitem', 'parameterdescription', 'entry'] or (element.tag == 'simplesect' and element.attrib['kind'] == 'return')) and not has_block_elements and paragraph_count == 1:
         assert out.parsed.startswith('<p>') and out.parsed.endswith('</p>')
         out.parsed = out.parsed[3:-4]
 
index 262d626581fe8da2c2de692eb8d4b20899e6e92c..2cb7ea849ee53f484398be6c41048feee74558a9 100644 (file)
@@ -39,7 +39,7 @@
         </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>
+<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>Yup</td><td>This</td></tr><tr><td>is a table</td><td><em>really</em></td><td>yes.</td></tr></tbody></table>
       </div>
     </div>
   </div>
index 04902cafe553bd6245c67350fe11c221117f7ea6..604d7ff2064658790fc927fe87e4d6c4ba21761a 100644 (file)
@@ -53,6 +53,12 @@ Text right after that blockquote should be a new paragraph.
 
 A paragraph after that list.
 
+Table header    | Another       | Third
+--------------- | ------------- | -----
+Cell            | Another cell  | 3rd
+Next row        | Yup           | This
+is a table      | *really*      | yes.
+
 */
 
 /** @page other Other page