summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-22 20:10:47 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-22 20:11:26 -0800
commitb142a396090798ed06e89475dcf6fd77362e312f (patch)
treeb91030c45c4dce88f427c87882fb265c39273e16
parent694a826bf0caef60330e3f4fcd195611a70ec77e (diff)
Fixed #214 C and JS implementations.
They were gobbling whitespace after shortcut reference links, e.g. [foo] bar [foo]: url Closes #214.
-rw-r--r--js/lib/inlines.js4
-rw-r--r--src/inlines.c10
2 files changed, 13 insertions, 1 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
index 1f4d194..96e8753 100644
--- a/js/lib/inlines.js
+++ b/js/lib/inlines.js
@@ -575,6 +575,10 @@ var parseCloseBracket = function(inlines) {
} else {
reflabel = this.subject.slice(beforelabel, beforelabel + n);
}
+ if (n === 0) {
+ // If shortcut reference link, rewind before spaces we skipped.
+ this.pos = savepos;
+ }
// lookup rawlabel in refmap
var link = this.refmap[normalizeReference(reflabel)];
diff --git a/src/inlines.c b/src/inlines.c
index 37ad768..9bc4e35 100644
--- a/src/inlines.c
+++ b/src/inlines.c
@@ -658,6 +658,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
cmark_node *link_text;
cmark_node *inl;
chunk raw_label;
+ int found_label;
advance(subj); // advance past ]
initial_pos = subj->pos;
@@ -717,12 +718,19 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
// skip spaces
subj->pos = subj->pos + scan_spacechars(&subj->input, subj->pos);
raw_label = chunk_literal("");
- if (!link_label(subj, &raw_label) || raw_label.len == 0) {
+ found_label = link_label(subj, &raw_label);
+ if (!found_label || raw_label.len == 0) {
chunk_free(&raw_label);
raw_label = chunk_dup(&subj->input, opener->position,
initial_pos - opener->position - 1);
}
+ if (!found_label) {
+ // If we have a shortcut reference link, back up
+ // to before the spacse we skipped.
+ subj->pos = initial_pos;
+ }
+
ref = reference_lookup(subj->refmap, &raw_label);
chunk_free(&raw_label);