From 1622f8f31262f18a4a3d99a6f5d30e900b224cec Mon Sep 17 00:00:00 2001 From: Nat Welch Date: Thu, 26 Nov 2015 22:11:25 +0000 Subject: [PATCH] Apply @miekg's patch From https://github.com/miekg/mmark/commit/99ce7134f6bf7b5b919d18ce5cc5099339b27e10.patch --- inline.go | 20 +++++++++++++++++--- inline_test.go | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/inline.go b/inline.go index a28bb66..0e41a3c 100644 --- a/inline.go +++ b/inline.go @@ -260,7 +260,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { } } - if i >= len(data) { + if i >= len(data) || brace > 0 { return 0 } @@ -285,14 +285,28 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { linkB := i - // look for link end: ' " ) + // look for link end: ' " ), check for new openning + // braces and take this into account, this may lead + // for overshooting and probably will require some + // finetuning. findlinkend: for i < len(data) { switch { case data[i] == '\\': i += 2 - case data[i] == ')' || data[i] == '\'' || data[i] == '"': + case data[i] == '(': + brace++ + i++ + + case data[i] == ')': + if brace <= 0 { + break findlinkend + } + brace-- + i++ + + case data[i] == '\'' || data[i] == '"': break findlinkend default: diff --git a/inline_test.go b/inline_test.go index d793e01..6227914 100644 --- a/inline_test.go +++ b/inline_test.go @@ -541,6 +541,20 @@ func TestInlineLink(t *testing.T) { "[link](<../>)\n", "

link

\n", + + // Issue 116 in blackfriday + "![](http://www.broadgate.co.uk/Content/Upload/DetailImages/Cyclus700(1).jpg)", + "

\"\"\n

\n", + + // no closing ), autolinking detects the url next + "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation) is the", + "

[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation) is the

\n", + + "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)) is the", + "

disambiguation is the

\n", + + "[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation))", + "

disambiguation

\n", } doLinkTestsInline(t, tests)