diff --git a/inline.go b/inline.go index d45bd94..a378a30 100644 --- a/inline.go +++ b/inline.go @@ -319,13 +319,25 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) { linkB := i // look for link end: ' " ) + brace := 0 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 + } + i++ + brace-- + + case data[i] == '\'' || data[i] == '"': break findlinkend default: diff --git a/inline_test.go b/inline_test.go index 5a91d8a..155ca9d 100644 --- a/inline_test.go +++ b/inline_test.go @@ -466,6 +466,19 @@ func TestInlineLink(t *testing.T) { "[link](<../>)\n", "

link

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

\"\"

\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)