Implement SkipLinks, add test
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 04 Apr 2016 14:08:35 +0300
2 files changed,
22 insertions(+),
2 deletions(-)
M
html.go
→
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 @@ //}
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 {
M
inline_test.go
→
inline_test.go
@@ -1114,5 +1114,18 @@ "<p>foo -- bar</p>\n",
"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, + }) }