diff --git a/src/ui/public/markdown/markdown.js b/src/ui/public/markdown/markdown.js index 2e2b47e37c7bc..d34a387af4cdf 100644 --- a/src/ui/public/markdown/markdown.js +++ b/src/ui/public/markdown/markdown.js @@ -48,10 +48,8 @@ export class Markdown extends Component { this.markdownIt = markdownFactory(this.props.whiteListedRules, this.props.openLinksInNewTab); this.state = { - renderedMarkdown: this.transformMarkdown(this.props) + renderedMarkdown: this.transformMarkdown(this.props), }; - - } /** @@ -68,9 +66,16 @@ export class Markdown extends Component { } componentWillReceiveProps(props) { - if (props.markdown !== this.props.markdown) { + const hasOpenLinksInNewTabChanged = props.openLinksInNewTab !== this.props.openLinksInNewTab; + const hasMarkdownChanged = props.markdown !== this.props.markdown; + const hasWhiteListerRulesChanged = props.whiteListedRules !== this.props.whiteListedRules; + + if (hasOpenLinksInNewTabChanged || hasWhiteListerRulesChanged) { + this.markdownIt = markdownFactory(props.whiteListedRules, props.openLinksInNewTab); + } + if (hasMarkdownChanged || hasOpenLinksInNewTabChanged || hasWhiteListerRulesChanged) { this.setState({ - renderedMarkdown: this.transformMarkdown(props) + renderedMarkdown: this.transformMarkdown(props), }); } } @@ -84,10 +89,7 @@ export class Markdown extends Component { ...rest } = this.props; - const classes = classNames( - 'markdown-body', - className - ); + const classes = classNames('markdown-body', className); return (