md_process_inlines: Fix link/image closers spanning over multiple lines. Fixes #40.
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
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 3607c5a..1646032 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3959,6 +3959,13 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
(opener->ch == '!' ? MD_SPAN_IMG : MD_SPAN_A),
STR(dest_mark->beg), dest_mark->end - dest_mark->beg, FALSE,
md_mark_get_ptr(ctx, title_mark - ctx->marks), title_mark->prev));
+
+ /* link/image closer may span multiple lines. */
+ if(mark->ch == ']') {
+ while(mark->end > line->end)
+ line++;
+ }
+
break;
}
@@ -4055,7 +4062,7 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
MD_TEXT(break_type, _T("\n"), 1);
}
- /* Switch to the following line. */
+ /* Move to the next line. */
line++;
off = line->beg;
diff --git a/test/coverage.txt b/test/coverage.txt
index ab4f75b..345d5d7 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -141,6 +141,16 @@ __x_ _x___
````````````````````````````````
+### [Issue 40](https://github.com/mity/md4c/issues/40)
+```````````````````````````````` example
+[x](url
+'title'
+)x
+.
+<p><a href="url" title="title">x</a>x</p>
+````````````````````````````````
+
+
## Code coverage