cmark

My personal build of CMark ✏️

Commit
53ef343a65e3da19d605cfb7e8909004cfac954e
Parent
733c2ea2818f5a369b74a594447361ed3eec1f21
Author
John MacFarlane <jgm@berkeley.edu>
Date

Allow a shortcut link before a (.

See jgm/CommonMark#427

Diffstat

1 file changed, 5 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/inlines.c 7 5 2
diff --git a/src/inlines.c b/src/inlines.c
@@ -799,7 +799,7 @@ noMatch:
 
 // Return a link, an image, or a literal close bracket.
 static cmark_node *handle_close_bracket(subject *subj) {
-  bufsize_t initial_pos;
+  bufsize_t initial_pos, after_link_text_pos;
   bufsize_t starturl, endurl, starttitle, endtitle, endall;
   bufsize_t n;
   bufsize_t sps;
@@ -833,6 +833,8 @@ static cmark_node *handle_close_bracket(subject *subj) {
   // Now we check to see if it's a link/image.
   is_image = opener->image;
 
+  after_link_text_pos = subj->pos;
+
   // First, look for an inline link.
   if (peek_char(subj) == '(' &&
       ((sps = scan_spacechars(&subj->input, subj->pos + 1)) > -1) &&
@@ -863,7 +865,8 @@ static cmark_node *handle_close_bracket(subject *subj) {
       goto match;
 
     } else {
-      goto noMatch;
+      // it could still be a shortcut reference link
+      subj->pos = after_link_text_pos;
     }
   }