Commit 4ef024fbb7e739a5861619726b45c7f6d157b25e

Martin Mitas 2018-05-29T23:30:02

md_process_inlines: Fix link/image closers spanning over multiple lines. Fixes #40.

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