all repos — grayfriday @ 607478a8ce5e5da6d7ab19469b507912ef20eccd

blackfriday fork with a few changes

Implement SkipLinks, add test
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 04 Apr 2016 14:08:35 +0300
commit

607478a8ce5e5da6d7ab19469b507912ef20eccd

parent

0774c060d74766118a136c287377ee95c9cd7cc2

2 files changed, 22 insertions(+), 2 deletions(-)

jump to
M html.gohtml.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.goinline_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, + }) }