diff options
author | Stefan Neuhaus <stefan@stefanneuhaus.org> | 2018-05-27 23:14:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-05-28 01:21:36 +0200 |
commit | 7a6192647a4b383cd539df2063388ea380371de6 (patch) | |
tree | d92376ddc8f851b3169a68f4450c68c65e914600 /helpers | |
parent | d68367cbe76cbc02adb5b778e8be98bed6319368 (diff) |
Add a BlackFriday option for rel="nofollow" on external links
Add a configuration option "nofollowLinks". When set to "true" the "HTML_NOFOLLOW_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "nofollow" value for the "rel" attribute.
Fixes #4722
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 6 | ||||
-rw-r--r-- | helpers/content_test.go | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/helpers/content.go b/helpers/content.go index d42995519..4a46ecb77 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -108,6 +108,7 @@ type BlackFriday struct { AngledQuotes bool Fractions bool HrefTargetBlank bool + NofollowLinks bool SmartDashes bool LatexDashes bool TaskLists bool @@ -124,6 +125,7 @@ func newBlackfriday(config map[string]interface{}) *BlackFriday { "smartypantsQuotesNBSP": false, "fractions": true, "hrefTargetBlank": false, + "nofollowLinks": false, "smartDashes": true, "latexDashes": true, "plainIDAnchors": true, @@ -277,6 +279,10 @@ func (c *ContentSpec) getHTMLRenderer(defaultFlags int, ctx *RenderingContext) b htmlFlags |= blackfriday.HTML_HREF_TARGET_BLANK } + if ctx.Config.NofollowLinks { + htmlFlags |= blackfriday.HTML_NOFOLLOW_LINKS + } + if ctx.Config.SmartDashes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_DASHES } diff --git a/helpers/content_test.go b/helpers/content_test.go index 2f8884c55..fe670bd74 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -204,6 +204,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) { {blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES}, {blackfriday.HTML_SMARTYPANTS_FRACTIONS}, {blackfriday.HTML_HREF_TARGET_BLANK}, + {blackfriday.HTML_NOFOLLOW_LINKS}, {blackfriday.HTML_SMARTYPANTS_DASHES}, {blackfriday.HTML_SMARTYPANTS_LATEX_DASHES}, } @@ -212,6 +213,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) { ctx.Config.AngledQuotes = true ctx.Config.Fractions = true ctx.Config.HrefTargetBlank = true + ctx.Config.NofollowLinks = true ctx.Config.LatexDashes = true ctx.Config.PlainIDAnchors = true ctx.Config.SmartDashes = true |