mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
handle parentheses inside of links
This commit is contained in:
parent
4c9bf95126
commit
9789b1389e
14
inline.go
14
inline.go
|
@ -319,13 +319,25 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
||||||
linkB := i
|
linkB := i
|
||||||
|
|
||||||
// look for link end: ' " )
|
// look for link end: ' " )
|
||||||
|
brace := 0
|
||||||
findlinkend:
|
findlinkend:
|
||||||
for i < len(data) {
|
for i < len(data) {
|
||||||
switch {
|
switch {
|
||||||
case data[i] == '\\':
|
case data[i] == '\\':
|
||||||
i += 2
|
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
|
break findlinkend
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -466,6 +466,19 @@ func TestInlineLink(t *testing.T) {
|
||||||
|
|
||||||
"[link](<../>)\n",
|
"[link](<../>)\n",
|
||||||
"<p><a href=\"../\">link</a></p>\n",
|
"<p><a href=\"../\">link</a></p>\n",
|
||||||
|
|
||||||
|
"![](http://www.broadgate.co.uk/Content/Upload/DetailImages/Cyclus700(1).jpg)",
|
||||||
|
"<p><img src=\"http://www.broadgate.co.uk/Content/Upload/DetailImages/Cyclus700(1).jpg\" alt=\"\" /></p>\n",
|
||||||
|
|
||||||
|
// no closing ), autolinking detects the url next
|
||||||
|
"[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation) is the",
|
||||||
|
"<p>[disambiguation](<a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation\">http://en.wikipedia.org/wiki/Disambiguation_(disambiguation</a>) is the</p>\n",
|
||||||
|
|
||||||
|
"[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)) is the",
|
||||||
|
"<p><a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)\">disambiguation</a> is the</p>\n",
|
||||||
|
|
||||||
|
"[disambiguation](http://en.wikipedia.org/wiki/Disambiguation_(disambiguation))",
|
||||||
|
"<p><a href=\"http://en.wikipedia.org/wiki/Disambiguation_(disambiguation)\">disambiguation</a></p>\n",
|
||||||
}
|
}
|
||||||
doLinkTestsInline(t, tests)
|
doLinkTestsInline(t, tests)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user