md_analyze_line: Fix mixing list and table parsing. If table header underline is not nested the same way as the preceding line (i.e. the wannabe table header line), then it cannot form a table. Fixes #41.
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 1646032..0efa34f 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -5549,12 +5549,6 @@ redo:
}
}
- /* Check whether we are table continuation. */
- if(pivot_line->type == MD_LINE_TABLE && md_is_table_row(ctx, off, &off)) {
- line->type = MD_LINE_TABLE;
- goto done;
- }
-
/* Check for "brother" container. I.e. whether we are another list item
* in already started list. */
if(n_parents < ctx->n_containers && n_brothers + n_children == 0) {
@@ -5646,6 +5640,14 @@ redo:
}
}
+ /* Check whether we are table continuation. */
+ if(pivot_line->type == MD_LINE_TABLE && md_is_table_row(ctx, off, &off) &&
+ n_parents == ctx->n_containers)
+ {
+ line->type = MD_LINE_TABLE;
+ goto done;
+ }
+
/* Check for ATX header. */
if(line->indent < ctx->code_indent_offset && CH(off) == _T('#')) {
unsigned level;
@@ -5689,7 +5691,8 @@ redo:
/* Check for table underline. */
if((ctx->r.flags & MD_FLAG_TABLES) && pivot_line->type == MD_LINE_TEXT &&
- (CH(off) == _T('|') || CH(off) == _T('-') || CH(off) == _T(':')))
+ (CH(off) == _T('|') || CH(off) == _T('-') || CH(off) == _T(':')) &&
+ n_parents == ctx->n_containers)
{
unsigned col_count;
diff --git a/test/tables.txt b/test/tables.txt
index 460fc2c..fc7a4da 100644
--- a/test/tables.txt
+++ b/test/tables.txt
@@ -270,3 +270,42 @@ baz | qux
quux | quuz</p>
````````````````````````````````
+
+
+## GitHub Issues
+
+### [Issue 41](https://github.com/mity/md4c/issues/41)
+```````````````````````````````` example
+* x|x
+---|---
+.
+<ul>
+<li>x|x
+---|---</li>
+</ul>
+````````````````````````````````
+(Not a table, because the underline has wrong indentation and is not part of the
+list item.)
+
+```````````````````````````````` example
+* x|x
+ ---|---
+x|x
+.
+<ul>
+<li><table>
+<thead>
+<tr>
+<th>x</th>
+<th>x</th>
+</tr>
+</thead>
+<tbody>
+</tbody>
+</table>
+</li>
+</ul>
+<p>x|x</p>
+````````````````````````````````
+(Here the underline has the right indentation so the table is detected.
+But the last line is not part of it due its indentation.)