From e60a5430b432a711a8c74bb733ad9ccbcd9d311f Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sun, 19 Mar 2017 15:26:43 -0700 Subject: [PATCH] Fix to replace only CodeBlock --- browser/components/MarkdownPreview.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 4c862a05..70d86819 100644 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -258,7 +258,15 @@ export default class MarkdownPreview extends React.Component { let { value, theme, indentSize, codeBlockTheme } = this.props this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme) - this.refs.root.contentWindow.document.body.innerHTML = markdown.render(encodeHTMLEntities(value)) + + const codeBlocks = value.match(/(```)(.|[\n])*?(```)/g) + if (codeBlocks.length > 0) { + codeBlocks.forEach((codeBlock) => { + const encodedCodeBlock = encodeHTMLEntities(codeBlock) + value = value.replace(codeBlock, encodedCodeBlock) + }) + } + this.refs.root.contentWindow.document.body.innerHTML = markdown.render(value) _.forEach(this.refs.root.contentWindow.document.querySelectorAll('.taskListItem'), (el) => { el.parentNode.parentNode.style.listStyleType = 'none'