diff --git a/html.go b/html.go index 6a3b7ce..284c871 100644 --- a/html.go +++ b/html.go @@ -35,6 +35,7 @@ const ( Safelink // Only link to trusted protocols NofollowLinks // Only link with rel="nofollow" NoreferrerLinks // Only link with rel="noreferrer" + NoopenerLinks // Only link with rel="noopener" HrefTargetBlank // Add a blank target CompletePage // Generate a complete HTML page UseXHTML // Generate XHTML output instead of HTML @@ -286,6 +287,9 @@ func appendLinkAttrs(attrs []string, flags HTMLFlags, link []byte) []string { if flags&NoreferrerLinks != 0 { val = append(val, "noreferrer") } + if flags&NoopenerLinks != 0 { + val = append(val, "noopener") + } if flags&HrefTargetBlank != 0 { attrs = append(attrs, "target=\"_blank\"") } diff --git a/inline_test.go b/inline_test.go index 9be9c8f..69b70ae 100644 --- a/inline_test.go +++ b/inline_test.go @@ -497,15 +497,26 @@ func TestRelAttrLink(t *testing.T) { HTMLFlags: Safelink | NoreferrerLinks, }) - var nofollownoreferrerTests = []string{ + var noopenerTests = []string{ "[foo](http://bar.com/foo/)\n", - "

foo

\n", + "

foo

\n", "[foo](/bar/)\n", "

foo

\n", } - doTestsInlineParam(t, nofollownoreferrerTests, TestParams{ - HTMLFlags: Safelink | NofollowLinks | NoreferrerLinks, + doTestsInlineParam(t, noopenerTests, TestParams{ + HTMLFlags: Safelink | NoopenerLinks, + }) + + var nofollownoreferrernoopenerTests = []string{ + "[foo](http://bar.com/foo/)\n", + "

foo

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

foo

\n", + } + doTestsInlineParam(t, nofollownoreferrernoopenerTests, TestParams{ + HTMLFlags: Safelink | NofollowLinks | NoreferrerLinks | NoopenerLinks, }) }