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:"))
|
||||
}
|
||||
|
||||
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 {
|
||||
pt := node.Parent.Type
|
||||
return pt != Link && pt != CodeBlock && pt != Code
|
||||
|
@ -1134,7 +1141,7 @@ func (r *HTML) RenderNode(w io.Writer, node *Node, entering bool) {
|
|||
case Link:
|
||||
// mark it but don't link it if it is not a safe link: no smartypants
|
||||
dest := node.LinkData.Destination
|
||||
if r.flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) {
|
||||
if needSkipLink(r.flags, dest) {
|
||||
if entering {
|
||||
r.out(w, tag("tt", nil, false))
|
||||
} else {
|
||||
|
|
|
@ -1114,5 +1114,18 @@ func TestDisableSmartDashes(t *testing.T) {
|
|||
"foo --- bar\n",
|
||||
"<p>foo --- bar</p>\n",
|
||||
}, 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