diff --git a/lib/marked.js b/lib/marked.js index f34e2df0bc..ac39650c77 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -721,9 +721,10 @@ InlineLexer.prototype.output = function(src) { if (cap = this.rules.link.exec(src)) { var lastParenIndex = findClosingBracket(cap[2], '()'); if (lastParenIndex > -1) { - var removeChars = cap[2].length - lastParenIndex; + var linkLen = cap[0].length - (cap[2].length - lastParenIndex) - (cap[3] || '').length; cap[2] = cap[2].substring(0, lastParenIndex); - cap[0] = cap[0].substring(0, cap[0].length - removeChars); + cap[0] = cap[0].substring(0, linkLen).trim(); + cap[3] = ''; } src = src.substring(cap[0].length); this.inLink = true; diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 5f46f53640..5dd1a065c8 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -113,10 +113,16 @@ "html": "

test@test.com

", "example": 1347 }, - { + { "section": "Emphasis extra tests", "markdown": "_test_. _test_: _test_! _test_? _test_-", "html": "

test. test: test! test? test-

", "example": 15 + }, + { + "section": "Links", + "markdown": "[One](https://example.com/1) ([Two](https://example.com/2)) [Three](https://example.com/3)", + "html": "

One (Two) Three

", + "example": 16 } ]