diff --git a/html.go b/html.go index 661322e..567d43a 100644 --- a/html.go +++ b/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 { diff --git a/inline_test.go b/inline_test.go index e16cab9..ccca327 100644 --- a/inline_test.go +++ b/inline_test.go @@ -1114,5 +1114,18 @@ func TestDisableSmartDashes(t *testing.T) { "foo --- bar\n", "

foo --- bar

\n", }, TestParams{ - Options: Options{Extensions: Smartypants | SmartypantsLatexDashes}}) + Options: Options{Extensions: Smartypants | SmartypantsLatexDashes}, + }) +} + +func TestSkipLinks(t *testing.T) { + doTestsInlineParam(t, []string{ + "[foo](gopher://foo.bar)", + "

foo

\n", + + "[foo](mailto://bar/)\n", + "

foo

\n", + }, TestParams{ + HTMLFlags: SkipLinks, + }) }