mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
commit
e078bb8ec3
4
html.go
4
html.go
|
@ -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>")
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user