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

Jocupi/external link indication #3108

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/bundle/src/renderMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

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.

img: ['alt', 'src']
},
allowedSchemes: ['data', 'http', 'https', 'ftp', 'mailto', 'sip', 'tel'],
Expand Down Expand Up @@ -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,
Expand All @@ -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)) {

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

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

Can you elaborate on the condition part? In the commit 6039f00 I'm adding localized strings as also requested by @compulim

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');
Expand Down
9 changes: 9 additions & 0 deletions packages/component/src/Styles/StyleSet/TextContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export default function createTextContentStyle({ bubbleMaxWidth, bubbleMinHeight
'& pre': {
overflow: 'hidden'
}
},
'& .externalLink': {
margin: 0,
padding: 0,
backgroundPosition: 'center right',
backgroundRepeat: 'no-repeat',
backgroundImage:
'linear-gradient(transparent,transparent),url(https://en.wikipedia.org/w/skins/Vector/resources/skins.vector.styles/images/external-link-ltr-icon.svg?b4b84)',
JorgeCupiV marked this conversation as resolved.
Show resolved Hide resolved
paddingRight: '13px'
}
};
}