mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Add target=_blank to all markdown links * add rel property * fix jest test
This commit is contained in:
parent
20a2a52183
commit
06b88edede
2 changed files with 14 additions and 1 deletions
|
@ -5,7 +5,7 @@ exports[`should render content with markdown 1`] = `
|
|||
className="kuiText kuiSubduedText tutorialContent markdown-body"
|
||||
dangerouslySetInnerHTML={
|
||||
Object {
|
||||
"__html": "<p>I am <em>some</em> <a href=\\"https://en.wikipedia.org/wiki/Content\\">content</a> with <code>markdown</code></p>
|
||||
"__html": "<p>I am <em>some</em> <a href=\\"https://en.wikipedia.org/wiki/Content\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">content</a> with <code>markdown</code></p>
|
||||
",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,19 @@ const markdownIt = new MarkdownIt('zero', { html: false, linkify: true });
|
|||
// list of rules can be found at https://github.com/markdown-it/markdown-it/issues/361
|
||||
markdownIt.enable(['backticks', 'emphasis', 'link', 'list']);
|
||||
|
||||
// All links should open in new browser tab.
|
||||
// Define custom renderer to add 'target' attribute
|
||||
// https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
|
||||
const originalLinkRender = markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) {
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
||||
tokens[idx].attrPush(['target', '_blank']);
|
||||
// https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/
|
||||
tokens[idx].attrPush(['rel', 'noopener noreferrer']);
|
||||
return originalLinkRender(tokens, idx, options, env, self);
|
||||
};
|
||||
|
||||
export function Content({ className, text }) {
|
||||
const classes = classNames('kuiText kuiSubduedText tutorialContent markdown-body', className);
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue