md_analyze_inlines: Resolve table cell boundaries before links. This brings some corner cases closer to cmark-gfm. Also fixes #51.
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
diff --git a/md4c/md4c.c b/md4c/md4c.c
index f584f55..8c4549f 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3793,15 +3793,9 @@ md_analyze_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mod
BACKTICK_OPENERS.tail = -1;
LOWERTHEN_OPENERS.head = -1;
LOWERTHEN_OPENERS.tail = -1;
- /* (2) Links. */
- md_analyze_marks(ctx, lines, n_lines, 0, ctx->n_marks, _T("[]!"));
- MD_CHECK(md_resolve_links(ctx, lines, n_lines));
- BRACKET_OPENERS.head = -1;
- BRACKET_OPENERS.tail = -1;
- ctx->unresolved_link_head = -1;
- ctx->unresolved_link_tail = -1;
+
if(table_mode) {
- /* (3a) Analyze table cell boundaries.
+ /* (2) Analyze table cell boundaries.
* Note we reset TABLECELLBOUNDARIES chain prior to the call md_analyze_marks(),
* not after, because caller may need it. */
MD_ASSERT(n_lines == 1);
@@ -3809,8 +3803,18 @@ md_analyze_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines, int table_mod
TABLECELLBOUNDARIES.tail = -1;
ctx->n_table_cell_boundaries = 0;
md_analyze_marks(ctx, lines, n_lines, 0, ctx->n_marks, _T("|"));
- } else {
- /* (3b) Emphasis and strong emphasis; permissive autolinks. */
+ }
+
+ /* (3) Links. */
+ md_analyze_marks(ctx, lines, n_lines, 0, ctx->n_marks, _T("[]!"));
+ MD_CHECK(md_resolve_links(ctx, lines, n_lines));
+ BRACKET_OPENERS.head = -1;
+ BRACKET_OPENERS.tail = -1;
+ ctx->unresolved_link_head = -1;
+ ctx->unresolved_link_tail = -1;
+
+ if(!table_mode) {
+ /* (4) Emphasis and strong emphasis; permissive autolinks. */
md_analyze_link_contents(ctx, lines, n_lines, 0, ctx->n_marks);
}
diff --git a/test/tables.txt b/test/tables.txt
index c06a4ce..ffda75d 100644
--- a/test/tables.txt
+++ b/test/tables.txt
@@ -248,11 +248,11 @@ quux | [quuz](/url2)
</table>
````````````````````````````````
-However pipes which are inside a link, an image or a code span are not
-recognized as cell boundaries.
+However pipes which are inside a code span are not recognized as cell
+boundaries.
```````````````````````````````` example
-Column 1 | [|](/url)
+Column 1 | Column 2
---------|---------
`foo | bar`
baz | qux
@@ -260,7 +260,7 @@ quux | quuz
.
<table>
<thead>
-<tr><th>Column 1</th><th><a href="/url">|</a></th></tr>
+<tr><th>Column 1</th><th>Column 2</th></tr>
</thead>
<tbody>
</tbody>