Skip to content

Commit

Permalink
No empty <tbody>
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Sep 11, 2017
1 parent d946b7c commit 3afbcad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
7 changes: 4 additions & 3 deletions extensions/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ static void html_render(cmark_syntax_extension *extension,
table_state->in_table_header = 1;
cmark_strbuf_puts(html, "<thead>");
cmark_html_render_cr(html);
} else if (!table_state->need_closing_table_body) {
cmark_strbuf_puts(html, "<tbody>");
cmark_html_render_cr(html);
table_state->need_closing_table_body = 1;
}
cmark_strbuf_puts(html, "<tr");
cmark_html_render_sourcepos(node, html, options);
Expand All @@ -587,9 +591,6 @@ static void html_render(cmark_syntax_extension *extension,
if (((node_table_row *)node->as.opaque)->is_header) {
cmark_html_render_cr(html);
cmark_strbuf_puts(html, "</thead>");
cmark_html_render_cr(html);
cmark_strbuf_puts(html, "<tbody>");
table_state->need_closing_table_body = 1;
table_state->in_table_header = false;
}
}
Expand Down
12 changes: 4 additions & 8 deletions test/extensions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,20 @@ Here we demonstrate some edge cases about what is and isn't a table.
<th>Just enough table</th>
<th>to be considered table</th>
</tr>
</thead>
<tbody></tbody></table>
</thead></table>
<p>| ---- | --- |</p>
<table>
<thead>
<tr>
<th>x</th>
</tr>
</thead>
<tbody></tbody></table>
</thead></table>
<table>
<thead>
<tr>
<th>xyz</th>
</tr>
</thead>
<tbody></tbody></table>
</thead></table>
````````````````````````````````

A "simpler" table, GFM style:
Expand Down Expand Up @@ -297,8 +294,7 @@ This shouldn't assert.
<tr>
<th>a</th>
</tr>
</thead>
<tbody></tbody></table>
</thead></table>
````````````````````````````````

### Escaping
Expand Down
15 changes: 15 additions & 0 deletions test/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,21 @@ cells are inserted. If there are greater, the excess is ignored:
</tr></tbody></table>
````````````````````````````````

If there are no rows in the body, no `<tbody>` is generated in HTML output:

```````````````````````````````` example table
| abc | def |
| --- | --- |
.
<table>
<thead>
<tr>
<th>abc</th>
<th>def</th>
</tr>
</thead></table>
````````````````````````````````

</div>

# Container blocks
Expand Down

0 comments on commit 3afbcad

Please sign in to comment.