Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

ycmjason
Copy link
Contributor

@ycmjason ycmjason commented May 7, 2018

Fixing #186

This approach adds a config which switches all external links to use blank or no blank.

Alt approaches: #356 #358

cc @ulivz @meteorlxy @mathiasbynens

Copy link

@mathiasbynens mathiasbynens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

Copy link
Member

@ulivz ulivz left a 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) {
Copy link
Member

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"`:
Copy link
Member

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.

@ulivz
Copy link
Member

ulivz commented May 8, 2018

Thanks for the great work! 👍Closing it and leverage #358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants