Commit 002f76c9750cc13315d4b23e3228cb09e548320a

Martin Mitas 2020-10-18T09:37:45

md_resolve_links: Skip [...] used as a reference link/image label. Fixes #131.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 964797c..e9affd4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,14 @@
 # MD4C Change Log
 
 
+## Next Version (Work in Progress)
+
+Fixes:
+
+* [#131](https://github.com/mity/md4c/issues/131):
+  Fix handling of a reference image nested in a reference link.
+
+
 ## Version 0.4.6
 
 Fixes:
diff --git a/src/md4c.c b/src/md4c.c
index 0119e7a..caa5fe7 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -3524,6 +3524,10 @@ md_resolve_links(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
             if(is_link) {
                 /* Eat the 2nd "[...]". */
                 closer->end = next_closer->end;
+
+                /* Do not analyze the label as a standalone link in the next
+                 * iteration. */
+                next_index = ctx->marks[next_index].prev;
             }
         } else {
             if(closer->end < ctx->size  &&  CH(closer->end) == _T('(')) {
diff --git a/test/coverage.txt b/test/coverage.txt
index 8367759..4b504e1 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -284,6 +284,18 @@ foo
 ````````````````````````````````
 
 
+### [Issue 131](https://github.com/mity/md4c/issues/131)
+
+```````````````````````````````` example
+[![alt][img]][link]
+
+[img]: img_url
+[link]: link_url
+.
+<p><a href="link_url"><img src="img_url" alt="alt"></a></p>
+````````````````````````````````
+
+
 ## Code coverage
 
 ### `md_is_unicode_whitespace__()`