md_process_table_block_contents: Suppress empty TBODY block generation. When the table has no body rows, do not call the callback with MD_BLOCK_TBODY events. Fixes #138.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ab5de4..3b465d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/md4c.c b/src/md4c.c
index 0cc905d..314000e 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -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);
diff --git a/test/tables.txt b/test/tables.txt
index 80147ab..bef5799 100644
--- a/test/tables.txt
+++ b/test/tables.txt
@@ -301,8 +301,6 @@ x|x
<th>x</th>
</tr>
</thead>
-<tbody>
-</tbody>
</table>
</li>
</ul>
@@ -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>
+````````````````````````````````