From ca3741fc868ff3b8441ce3e495291ce9557d68fd Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 3 Oct 2019 09:32:18 -0500 Subject: [PATCH] fix image parens --- lib/marked.js | 3 ++- test/specs/new/image_paren.html | 3 +++ test/specs/new/image_paren.md | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/image_paren.html create mode 100644 test/specs/new/image_paren.md diff --git a/lib/marked.js b/lib/marked.js index c0db7ee6b5..773341f48a 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -723,7 +723,8 @@ InlineLexer.prototype.output = function(src) { if (cap = this.rules.link.exec(src)) { var lastParenIndex = findClosingBracket(cap[2], '()'); if (lastParenIndex > -1) { - var linkLen = 4 + cap[1].length + lastParenIndex; + var start = cap[0].indexOf('!') === 0 ? 5 : 4; + var linkLen = start + cap[1].length + lastParenIndex; cap[2] = cap[2].substring(0, lastParenIndex); cap[0] = cap[0].substring(0, linkLen).trim(); cap[3] = ''; diff --git a/test/specs/new/image_paren.html b/test/specs/new/image_paren.html new file mode 100644 index 0000000000..4a5e2fe420 --- /dev/null +++ b/test/specs/new/image_paren.html @@ -0,0 +1,3 @@ +

(or )

+ +

one (or two)

diff --git a/test/specs/new/image_paren.md b/test/specs/new/image_paren.md new file mode 100644 index 0000000000..a565143964 --- /dev/null +++ b/test/specs/new/image_paren.md @@ -0,0 +1,3 @@ +![](img1.svg) (or ![](img2.svg)) + +![one](img1.svg) (or ![two](img2.svg))