-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added global config for external links #357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only small things.
@@ -14,8 +15,10 @@ module.exports = md => { | |||
const isExternal = /^https?:/.test(href) | |||
const isSourceLink = /(\/|\.md|\.html)(#.*)?$/.test(href) | |||
if (isExternal) { | |||
addAttr(token, 'target', '_blank') | |||
addAttr(token, 'rel', 'noopener noreferrer') | |||
if (opts.blank) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank
should only control the target
, and noopener
and noreferrer
are both worth to be added to external links by default.
See: Opens External Anchors Using rel="noopener"
Adding a rel="noopener" attribute prevents the new page from being able to access the window.opener property and will ensure it runs in a separate process. The rel="noreferrer" attribute has the same effect, but will also prevent the Referer header from being sent to the new page. See HTML Standard: Link type "noreferrer" for an explanation of this behavior.
Also see: The performance benefits of rel=noopener
If you have links to another origin, you should use rel="noopener".
@@ -48,11 +48,13 @@ Given the following directory structure: | |||
|
|||
### External Links | |||
|
|||
Outbound links automatically gets `target="_blank"`: | |||
Outbound links automatically gets `target="_blank" rel="noopener noreferrer"`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rel="noopener noreferrer"
should be remained here.
Thanks for the great work! 👍Closing it and leverage #358 |
Fixing #186
This approach adds a config which switches all external links to use
blank
or noblank
.Alt approaches: #356 #358
cc @ulivz @meteorlxy @mathiasbynens