-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// markdown-it plugin for: | ||
// 1. adding target="_blank" to external links | ||
// 1. adding target="_blank" and rel="noopener noreferrer" to external links | ||
// (if opts.blank is true) | ||
// 2. converting internal links to <router-link> | ||
|
||
module.exports = md => { | ||
module.exports = (md, opts) => { | ||
let hasOpenRouterLink = false | ||
|
||
md.renderer.rules.link_open = (tokens, idx, options, env, self) => { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
See: Opens External Anchors Using rel="noopener"
Also see: The performance benefits of rel=noopener
|
||
addAttr(token, 'target', '_blank') | ||
addAttr(token, 'rel', 'noopener noreferrer') | ||
} | ||
} else if (isSourceLink) { | ||
hasOpenRouterLink = true | ||
tokens[idx] = toRouterLink(token, link) | ||
|
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.