mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Implement SkipLinks, add test
This commit is contained in:
parent
0774c060d7
commit
607478a8ce
9
html.go
9
html.go
|
@ -999,6 +999,13 @@ func isMailto(link []byte) bool {
|
||||||
return bytes.HasPrefix(link, []byte("mailto:"))
|
return bytes.HasPrefix(link, []byte("mailto:"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func needSkipLink(flags HTMLFlags, dest []byte) bool {
|
||||||
|
if flags&SkipLinks != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest)
|
||||||
|
}
|
||||||
|
|
||||||
func isSmartypantable(node *Node) bool {
|
func isSmartypantable(node *Node) bool {
|
||||||
pt := node.Parent.Type
|
pt := node.Parent.Type
|
||||||
return pt != Link && pt != CodeBlock && pt != Code
|
return pt != Link && pt != CodeBlock && pt != Code
|
||||||
|
@ -1134,7 +1141,7 @@ func (r *HTML) RenderNode(w io.Writer, node *Node, entering bool) {
|
||||||
case Link:
|
case Link:
|
||||||
// mark it but don't link it if it is not a safe link: no smartypants
|
// mark it but don't link it if it is not a safe link: no smartypants
|
||||||
dest := node.LinkData.Destination
|
dest := node.LinkData.Destination
|
||||||
if r.flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) {
|
if needSkipLink(r.flags, dest) {
|
||||||
if entering {
|
if entering {
|
||||||
r.out(w, tag("tt", nil, false))
|
r.out(w, tag("tt", nil, false))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1114,5 +1114,18 @@ func TestDisableSmartDashes(t *testing.T) {
|
||||||
"foo --- bar\n",
|
"foo --- bar\n",
|
||||||
"<p>foo --- bar</p>\n",
|
"<p>foo --- bar</p>\n",
|
||||||
}, TestParams{
|
}, TestParams{
|
||||||
Options: Options{Extensions: Smartypants | SmartypantsLatexDashes}})
|
Options: Options{Extensions: Smartypants | SmartypantsLatexDashes},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkipLinks(t *testing.T) {
|
||||||
|
doTestsInlineParam(t, []string{
|
||||||
|
"[foo](gopher://foo.bar)",
|
||||||
|
"<p><tt>foo</tt></p>\n",
|
||||||
|
|
||||||
|
"[foo](mailto://bar/)\n",
|
||||||
|
"<p><tt>foo</tt></p>\n",
|
||||||
|
}, TestParams{
|
||||||
|
HTMLFlags: SkipLinks,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user