mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-26 20:14:43 +01:00
parent
300106c228
commit
1622f8f312
20
inline.go
20
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:
|
||||
|
@ -541,6 +541,20 @@ func TestInlineLink(t *testing.T) {
|
||||
|
||||
"[link](<../>)\n",
|
||||
"<p><a href=\"../\">link</a></p>\n",
|
||||
|
||||
// Issue 116 in blackfriday
|
||||
"![](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=\"\" />\n</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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user