Skip to content

Commit a4d6e1f

Browse files
committed
TextNode characters are re-escaped in htmlWidgets now. Fixes #1533
1 parent c2171a0 commit a4d6e1f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/web/utils/htmlWidget.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import {WidgetType, Decoration, ViewPlugin} from "@codemirror/view";
88
import {escapeControlChars} from "./editorUtils.mjs";
99
import {htmlCopyOverride} from "./copyOverride.mjs";
10+
import Utils from "../../core/Utils.mjs";
1011

1112

1213
/**
@@ -64,7 +65,11 @@ class HTMLWidget extends WidgetType {
6465
* @param {DOMNode} textNode
6566
*/
6667
replaceControlChars(textNode) {
67-
const val = escapeControlChars(textNode.nodeValue, true, this.view.state.lineBreak);
68+
// .nodeValue unencodes HTML encoding such as &lt; to "<"
69+
// We must remember to escape any potential HTML in TextNodes as we do not
70+
// want to render it.
71+
const textValue = Utils.escapeHtml(textNode.nodeValue);
72+
const val = escapeControlChars(textValue, true, this.view.state.lineBreak);
6873
if (val.length !== textNode.nodeValue.length) {
6974
const node = document.createElement("span");
7075
node.innerHTML = val;

0 commit comments

Comments
 (0)