Skip to content

Commit

Permalink
[home] Add target=_blank to all markdown links (#15995) (#16006)
Browse files Browse the repository at this point in the history
* Add target=_blank to all markdown links

* add rel property

* fix jest test
  • Loading branch information
nreese authored Jan 12, 2018
1 parent 20a2a52 commit 06b88ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
",
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/core_plugins/kibana/public/home/components/tutorial/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 06b88ed

Please sign in to comment.