-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Jocupi/external link indication #3108
Closed
JorgeCupiV
wants to merge
5
commits into
microsoft:master
from
JorgeCupiV:jocupi/external-link-indication
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
201644d
FIX: Add style that adds an 'external' icon for external links
f995da4
FIX: Add 'Opens in a new window' title to links that open in a new wi…
378ba7b
FIX: Add method to check if a link is external or not
6039f00
FIX: Add localized strings for text that is displayed as title for in…
4dd7434
FIX: Changes external link icon for one approved and obtained from Of…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import sanitizeHTML from 'sanitize-html'; | |
|
||
const SANITIZE_HTML_OPTIONS = { | ||
allowedAttributes: { | ||
a: ['aria-label', 'href', 'name', 'target', 'title'], | ||
a: ['aria-label', 'href', 'name', 'target', 'title', 'role', 'class'], | ||
img: ['alt', 'src'] | ||
}, | ||
allowedSchemes: ['data', 'http', 'https', 'ftp', 'mailto', 'sip', 'tel'], | ||
|
@@ -48,6 +48,10 @@ const SANITIZE_HTML_OPTIONS = { | |
] | ||
}; | ||
|
||
function isExternal(url) { | ||
return url.host !== window.location.host; | ||
} | ||
|
||
const customMarkdownIt = new MarkdownIt({ | ||
breaks: false, | ||
html: false, | ||
|
@@ -65,6 +69,14 @@ const customMarkdownIt = new MarkdownIt({ | |
tokens[index].attrs[targetAttrIndex][1] = '_blank'; | ||
} else { | ||
tokens[index].attrPush(['target', '_blank']); | ||
tokens[index].attrPush(['class', 'externalLink']); | ||
} | ||
|
||
const urlAttrIndex = tokens[index].attrIndex('href'); | ||
if (isExternal(urlAttrIndex)) { | ||
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. These should be conditionally added since the markdown author could supply their own title 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. |
||
tokens[index].attrPush(['title', 'Opens in a new window, external']); | ||
} else { | ||
tokens[index].attrPush(['title', 'Opens in a new window']); | ||
} | ||
|
||
const relAttrIndex = tokens[index].attrIndex('rel'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think that 'class' belongs in this list. As my understanding is that these are supported markdown attributes and we don't want the markdown author to support overriding this behavior.
It also looks like role was added as part of this change, but not necessarily used. It might be left over from another change you inherited.