Skip to content

Commit

Permalink
Merge pull request #3531 from quilljs/zh-no-escape-code
Browse files Browse the repository at this point in the history
Move code escaping to `html()`
  • Loading branch information
jhchen authored Feb 11, 2022
2 parents cf9d835 + 0de0077 commit 885f1a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions formats/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<pre>\n${this.code(index, length)}\n</pre>`;
return `<pre>\n${escapeText(this.code(index, length))}\n</pre>`;
}
}

Expand Down
5 changes: 2 additions & 3 deletions modules/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ class SyntaxCodeBlockContainer extends CodeBlockContainer {
? SyntaxCodeBlock.formats(codeBlock.domNode)
: 'plain';

return `<pre data-language="${language}">\n${this.code(
index,
length,
return `<pre data-language="${language}">\n${escapeText(
this.code(index, length),
)}\n</pre>`;
}

Expand Down

0 comments on commit 885f1a2

Please sign in to comment.