Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
7be19db4
Commit
7be19db4
authored
Jun 08, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set target="_blank" for external links
parent
e6daf1f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
1 deletion
+14
-1
lib/banzai/filter/external_link_filter.rb
lib/banzai/filter/external_link_filter.rb
+3
-0
spec/features/markdown_spec.rb
spec/features/markdown_spec.rb
+10
-0
spec/fixtures/markdown.md.erb
spec/fixtures/markdown.md.erb
+1
-1
No files found.
lib/banzai/filter/external_link_filter.rb
View file @
7be19db4
...
@@ -15,6 +15,9 @@ module Banzai
...
@@ -15,6 +15,9 @@ module Banzai
next
if
link
.
start_with?
(
internal_url
)
next
if
link
.
start_with?
(
internal_url
)
node
.
set_attribute
(
'rel'
,
'nofollow noreferrer'
)
node
.
set_attribute
(
'rel'
,
'nofollow noreferrer'
)
# Open external links on a new tab
node
.
set_attribute
(
'target'
,
'_blank'
)
end
end
doc
doc
...
...
spec/features/markdown_spec.rb
View file @
7be19db4
...
@@ -173,10 +173,20 @@ describe 'GitLab Markdown', feature: true do
...
@@ -173,10 +173,20 @@ describe 'GitLab Markdown', feature: true do
expect
(
link
.
attr
(
'rel'
)).
to
include
(
'noreferrer'
)
expect
(
link
.
attr
(
'rel'
)).
to
include
(
'noreferrer'
)
end
end
it
'adds _blank to target attribute for external links'
do
link
=
doc
.
at_css
(
'a:contains("Google")'
)
expect
(
link
.
attr
(
'target'
)).
to
match
(
'_blank'
)
end
it
'ignores internal link'
do
it
'ignores internal link'
do
link
=
doc
.
at_css
(
'a:contains("GitLab Root")'
)
link
=
doc
.
at_css
(
'a:contains("GitLab Root")'
)
expect
(
link
.
attr
(
'rel'
)).
not_to
match
'nofollow'
expect
(
link
.
attr
(
'rel'
)).
not_to
match
'nofollow'
end
end
it
'does not set _blank to target attribute for internal links'
do
link
=
doc
.
at_css
(
'a:contains("GitLab Root")'
)
expect
(
link
.
attr
(
'target'
)).
not_to
match
'_blank'
end
end
end
end
end
...
...
spec/fixtures/markdown.md.erb
View file @
7be19db4
...
@@ -136,7 +136,7 @@ But it shouldn't autolink text inside certain tags:
...
@@ -136,7 +136,7 @@ But it shouldn't autolink text inside certain tags:
### ExternalLinkFilter
### ExternalLinkFilter
External links get a `rel="nofollow
"` attribute
:
External links get a `rel="nofollow
noreferrer"` and `target="_blank"` attributes
:
- [Google](https://google.com/)
- [Google](https://google.com/)
- [GitLab Root](
<%=
Gitlab
.
config
.
gitlab
.
url
%>
)
- [GitLab Root](
<%=
Gitlab
.
config
.
gitlab
.
url
%>
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment