chiark / gitweb /
doxygen: more flexible table rendering.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 21:12:39 +0000 (22:12 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 29 Jan 2018 22:54:22 +0000 (23:54 +0100)
Support more consecutive table header rows, allow <th> elements inside
<tbody>.

doxygen/dox2html5.py
doxygen/test/contents_blocks/index.html
doxygen/test/contents_blocks/input.dox

index c32f860d26178cf52e33fc63c8ddf7ed9cc3d62c..8d28627ea616d93cf40bcd5be754bc450b92febb 100755 (executable)
@@ -448,6 +448,7 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             has_block_elements = True
             out.parsed += '<table class="m-table{}">'.format(
                 ' ' + add_css_class if add_css_class else '')
+            thead_written = False
             inside_tbody = False
 
             row: ET.Element
@@ -460,12 +461,23 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
                     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))
+
+                # Table head is opened upon encountering first header row
+                # and closed upon encountering first body row (in case it was
+                # ever opened). Encountering header row inside body again will
+                # not do anything special.
                 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
+                    if not thead_written:
+                        out.parsed += '<thead>'
+                        thead_written = True
                 else:
-                    out.parsed += '<tr>{}</tr>'.format(row_data)
+                    if thead_written and not inside_tbody:
+                        out.parsed += '</thead>'
+                    if not inside_tbody:
+                        out.parsed += '<tbody>'
+                        inside_tbody = True
+
+                out.parsed += '<tr>{}</tr>'.format(row_data)
 
             if inside_tbody: out.parsed += '</tbody>'
             out.parsed += '</table>'
index 965c0416506ce563859df26bdba11a379ced3409..5a7be91b1ceee6cd0b2b23bcc3dd36aec7de7c2d 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><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>
+<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"><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>
       </div>
     </div>
   </div>
index 2f1a1e7b45ce0bdaa838e4a1f4832b87e3f75830..2ca6bd96c981e6b32254a2a841cf66c9bb4eb9fe 100644 (file)
@@ -59,6 +59,21 @@ Cell            | Another cell  | 3rd
 Next row        |               | This
 is a table      | *really*      | yes.
 
+<table>
+  <tr>
+    <th>Table</th>
+    <th>with</th>
+  </tr>
+  <tr>
+    <th>two</th>
+    <th>row</th>
+  </tr>
+  <tr>
+    <td>table</td>
+    <td>header</td>
+  </tr>
+</table>
+
 @attention
     Attention, first paragraph.
 @attention