Skip to content

Commit

Permalink
md_process_table_block_contents: Suppress empty TBODY block generation.
Browse files Browse the repository at this point in the history
When the table has no body rows, do not call the callback with
MD_BLOCK_TBODY events.

Fixes #138.
  • Loading branch information
mity committed Nov 13, 2020
1 parent a997cb2 commit 3254b7c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Fixes:
Handle unmatched parenthesis pairs inside a permissive URL and WWW auto-links
in a way more compatible with the GFM.

* [#138](https://github.com/mity/md4c/issues/138):
The tag `<tbody></tbody>` is suppressed whenever the table has zero body
rows.


## Version 0.4.6

Expand Down
12 changes: 7 additions & 5 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -4507,12 +4507,14 @@ md_process_table_block_contents(MD_CTX* ctx, int col_count, const MD_LINE* lines
lines[0].beg, lines[0].end, align, col_count));
MD_LEAVE_BLOCK(MD_BLOCK_THEAD, NULL);

MD_ENTER_BLOCK(MD_BLOCK_TBODY, NULL);
for(i = 2; i < n_lines; i++) {
MD_CHECK(md_process_table_row(ctx, MD_BLOCK_TD,
lines[i].beg, lines[i].end, align, col_count));
if(n_lines > 2) {
MD_ENTER_BLOCK(MD_BLOCK_TBODY, NULL);
for(i = 2; i < n_lines; i++) {
MD_CHECK(md_process_table_row(ctx, MD_BLOCK_TD,
lines[i].beg, lines[i].end, align, col_count));
}
MD_LEAVE_BLOCK(MD_BLOCK_TBODY, NULL);
}
MD_LEAVE_BLOCK(MD_BLOCK_TBODY, NULL);

abort:
free(align);
Expand Down
19 changes: 17 additions & 2 deletions test/tables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ x|x
<th>x</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</li>
</ul>
Expand Down Expand Up @@ -361,3 +359,20 @@ A | B
</tbody>
</table>
````````````````````````````````


### [Issue 138](https://github.com/mity/md4c/issues/138)

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

0 comments on commit 3254b7c

Please sign in to comment.