diff --git a/formats/code.js b/formats/code.js index edb653eca2..84340620cc 100644 --- a/formats/code.js +++ b/formats/code.js @@ -14,17 +14,16 @@ class CodeBlockContainer extends Container { } code(index, length) { - const text = this.children + return this.children .map(child => (child.length() <= 1 ? '' : child.domNode.innerText)) .join('\n') .slice(index, index + length); - return escapeText(text); } html(index, length) { // `\n`s are needed in order to support empty lines at the beginning and the end. // https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions - return `
\n${this.code(index, length)}\n`; + return `
\n${escapeText(this.code(index, length))}\n`; } } diff --git a/modules/syntax.js b/modules/syntax.js index 70e135423a..da91073a89 100644 --- a/modules/syntax.js +++ b/modules/syntax.js @@ -141,9 +141,8 @@ class SyntaxCodeBlockContainer extends CodeBlockContainer { ? SyntaxCodeBlock.formats(codeBlock.domNode) : 'plain'; - return `
\n${this.code( - index, - length, + return `\n${escapeText( + this.code(index, length), )}\n`; }