summaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-12-25 16:24:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-12-25 16:24:20 -0700
commitf15108cca883005749b8bee3d020d50b9803b570 (patch)
treeb059d5f96267573c06aeb202822f087096683c41 /js/lib
parentff249740f11065eca2ba458b856638e2bfff16f3 (diff)
JS: fixed parsing of link-in-link-in-image.
Partially addresses #252. Still need to: - update C parser. - put an example in the spec.
Diffstat (limited to 'js/lib')
-rw-r--r--js/lib/inlines.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
index 994cc1e..fe4e947 100644
--- a/js/lib/inlines.js
+++ b/js/lib/inlines.js
@@ -280,7 +280,8 @@ var parseEmphasis = function(cc,inlines) {
previous: this.delimiters,
next: null,
can_open: res.can_open,
- can_close: res.can_close};
+ can_close: res.can_close,
+ active: true };
if (this.delimiters.previous !== null) {
this.delimiters.previous.next = this.delimiters;
}
@@ -460,7 +461,8 @@ var parseOpenBracket = function(inlines) {
next: null,
can_open: true,
can_close: false,
- index: startpos };
+ index: startpos,
+ active: true };
if (this.delimiters.previous !== null) {
this.delimiters.previous.next = this.delimiters;
}
@@ -487,7 +489,8 @@ var parseBang = function(inlines) {
next: null,
can_open: true,
can_close: false,
- index: startpos + 1 };
+ index: startpos + 1,
+ active: true };
if (this.delimiters.previous !== null) {
this.delimiters.previous.next = this.delimiters;
}
@@ -510,12 +513,12 @@ var parseCloseBracket = function(inlines) {
var link_text;
var i;
var reflabel;
- var opener, closer_above;
+ var opener;
this.pos += 1;
startpos = this.pos;
- // look through stack of delimiters for a [ or !
+ // look through stack of delimiters for a [ or ![
opener = this.delimiters;
while (opener !== null) {
@@ -531,6 +534,14 @@ var parseCloseBracket = function(inlines) {
return true;
}
+ if (!opener.active) {
+ // no matched opener, just return a literal
+ inlines.push(Str("]"));
+ // take opener off emphasis stack
+ this.removeDelimiter(opener);
+ return true;
+ }
+
// If we got here, open is a potential opener
is_image = opener.cc === C_BANG;
// instead of copying a slice, we null out the
@@ -595,14 +606,13 @@ var parseCloseBracket = function(inlines) {
}
// processEmphasis will remove this and later delimiters.
- // Now, for a link, we also remove earlier link openers.
+ // Now, for a link, we also deactivate earlier link openers.
// (no links in links)
if (!is_image) {
opener = this.delimiters;
- closer_above = null;
while (opener !== null) {
if (opener.cc === C_OPEN_BRACKET) {
- this.removeDelimiter(opener); // remove this opener from stack
+ opener.active = false; // deactivate this opener
}
opener = opener.previous;
}