diff --git a/src/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap b/src/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap index 922c6d013f3e4..95d8e79fb5eef 100644 --- a/src/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap +++ b/src/core_plugins/kibana/public/home/components/tutorial/__snapshots__/content.test.js.snap @@ -5,7 +5,7 @@ exports[`should render content with markdown 1`] = ` className="kuiText kuiSubduedText tutorialContent markdown-body" dangerouslySetInnerHTML={ Object { - "__html": "

I am some content with markdown

+ "__html": "

I am some content with markdown

", } } diff --git a/src/core_plugins/kibana/public/home/components/tutorial/content.js b/src/core_plugins/kibana/public/home/components/tutorial/content.js index 9b3e2e80bb94f..abba5839bb30a 100644 --- a/src/core_plugins/kibana/public/home/components/tutorial/content.js +++ b/src/core_plugins/kibana/public/home/components/tutorial/content.js @@ -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 (