Merge pull request #3904 from matrix-org/jryans/report-admin-external-links

Treat links as external in report content admin message
pull/21833/head
J. Ryan Stinnett 2020-01-23 01:06:42 +00:00 committed by GitHub
commit 1fdd155dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -91,7 +91,7 @@ export default class Markdown {
return true; return true;
} }
toHTML() { toHTML({ externalLinks = false } = {}) {
const renderer = new commonmark.HtmlRenderer({ const renderer = new commonmark.HtmlRenderer({
safe: false, safe: false,
@ -125,6 +125,24 @@ export default class Markdown {
} }
}; };
renderer.link = function(node, entering) {
const attrs = this.attrs(node);
if (entering) {
attrs.push(['href', this.esc(node.destination)]);
if (node.title) {
attrs.push(['title', this.esc(node.title)]);
}
// Modified link behaviour to treat them all as external and
// thus opening in a new tab.
if (externalLinks) {
attrs.push(['target', '_blank']);
attrs.push(['rel', 'noopener']);
}
this.tag('a', attrs);
} else {
this.tag('/a');
}
};
renderer.html_inline = html_if_tag_allowed; renderer.html_inline = html_if_tag_allowed;

View File

@ -102,7 +102,7 @@ export default class ReportEventDialog extends PureComponent {
SdkConfig.get().reportEvent.adminMessageMD; SdkConfig.get().reportEvent.adminMessageMD;
let adminMessage; let adminMessage;
if (adminMessageMD) { if (adminMessageMD) {
const html = new Markdown(adminMessageMD).toHTML(); const html = new Markdown(adminMessageMD).toHTML({ externalLinks: true });
adminMessage = <p dangerouslySetInnerHTML={{ __html: html }} />; adminMessage = <p dangerouslySetInnerHTML={{ __html: html }} />;
} }