Merge pull request #52 from laslowh/master

add HTML_NOFOLLOW_LINKS
This commit is contained in:
Vytautas Šaltenis 2014-03-10 21:47:35 +02:00
commit e078bb8ec3
2 changed files with 12 additions and 0 deletions

View File

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

View File

@ -421,6 +421,14 @@ func TestInlineLink(t *testing.T) {
doTestsInline(t, tests) 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) { func TestSafeInlineLink(t *testing.T) {
var tests = []string{ var tests = []string{
"[foo](/bar/)\n", "[foo](/bar/)\n",