add HTML_NOFOLLOW_LINKS

pull/52/head
Graham Miller 2014-02-25 09:21:57 -05:00
parent 5405274d99
commit d71c759108
2 changed files with 12 additions and 0 deletions

View File

@ -30,6 +30,7 @@ const (
HTML_SKIP_LINKS // skip all links
HTML_SKIP_SCRIPT // skip embedded <script> elements
HTML_SAFELINK // only link to trusted protocols
HTML_NOFOLLOW_LINKS // only link with rel="nofollow"
HTML_TOC // generate a table of contents
HTML_OMIT_CONTENTS // skip the main contents (for a standalone table of contents)
HTML_COMPLETE_PAGE // generate a complete HTML page
@ -499,6 +500,9 @@ func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content
out.WriteString("\" title=\"")
attrEscape(out, title)
}
if options.flags&HTML_NOFOLLOW_LINKS != 0 {
out.WriteString("\" rel=\"nofollow")
}
out.WriteString("\">")
out.Write(content)
out.WriteString("</a>")

View File

@ -421,6 +421,14 @@ func TestInlineLink(t *testing.T) {
doTestsInline(t, tests)
}
func TestNofollowLink(t *testing.T) {
var tests = []string{
"[foo](/bar/)\n",
"<p><a href=\"/bar/\" rel=\"nofollow\">foo</a></p>\n",
}
doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_NOFOLLOW_LINKS)
}
func TestSafeInlineLink(t *testing.T) {
var tests = []string{
"[foo](/bar/)\n",