diff --git a/src/Documentation/Markdown/Markdown.js b/src/Documentation/Markdown/Markdown.js index 257ec8e028..2aefb55169 100644 --- a/src/Documentation/Markdown/Markdown.js +++ b/src/Documentation/Markdown/Markdown.js @@ -104,6 +104,27 @@ CodeBlock.propTypes = { value: PropTypes.node.isRequired } +const Link = ({ children, ...props }) => { + const externalLink = props.href.match(/^(\/\/|http(s)?:\/\/)/) + const showIcon = + externalLink && children && typeof children[0].props.children === 'string' + + const modifiedProps = externalLink + ? { ...props, target: '_blank', rel: 'noopener nofollow' } + : props + + if (showIcon) { + return {children} + } + + return {children} +} + +Link.propTypes = { + children: PropTypes.node.isRequired, + href: PropTypes.string.isRequired +} + export default class Markdown extends React.PureComponent { constructor() { super() @@ -167,6 +188,7 @@ export default class Markdown extends React.PureComponent { escapeHtml={false} source={markdown} renderers={{ + link: Link, code: CodeBlock, heading: HeadingRenderer, virtualHtml: HtmlRenderer @@ -366,3 +388,16 @@ export const GithubLink = styled(LightButton)` background-image: url(/static/img/github_icon.svg); } ` + +const ExternalLink = styled.a` + &:after { + position: relative; + top: 1px; + right: 0; + width: 12px; + height: 12px; + margin-left: 1px; + /* Icon source https://en.wikipedia.org/w/skins/Vector/images/external-link-ltr-icon.svg */ + content: url(/static/img/external-link.svg); + } +` diff --git a/static/img/external-link.svg b/static/img/external-link.svg new file mode 100644 index 0000000000..12c3cc92f1 --- /dev/null +++ b/static/img/external-link.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file