From 1521414cadf9336e9adfec4a31ce65e5b45834c6 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 9 Jul 2026 13:25:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(code-runner):=20=E4=BF=AE=E5=A4=8D=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=86=85=E8=BF=90=E8=A1=8C=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=B8=8D=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resultArea 挂在 ProseMirror 可编辑文档树内部,浏览器对 contenteditable 子树强制 white-space 折叠(computed 为 collapse),CSS 的 white-space: pre-wrap 被覆盖,导致 textContent 里的 \n 与行首空格被吞、多行输出挤成一行。 改用
显式渲染换行、\u00A0 替换空格/制表符以保留对齐——二者均不依赖 white-space。createTextNode 避免 stdout 含 HTML 标签时的注入。 --- libs/tiptap-editor/src/code-block-view.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/tiptap-editor/src/code-block-view.ts b/libs/tiptap-editor/src/code-block-view.ts index 0c69c8c..abfbc2d 100644 --- a/libs/tiptap-editor/src/code-block-view.ts +++ b/libs/tiptap-editor/src/code-block-view.ts @@ -221,7 +221,22 @@ export class CodeBlockNodeView { this.resultArea.setAttribute('contenteditable', 'false'); this.container.appendChild(this.resultArea); } - this.resultArea.textContent = initial; + // resultArea 位于 ProseMirror 可编辑文档树内部。浏览器对 contenteditable 子树强制 + // white-space 折叠(此处 computed 为 collapse),CSS 里的 white-space: pre-wrap 被覆盖, + // 导致 textContent 里的 \n 与行首空格被吞掉、输出挤成一行。这里改用
渲染换行、 + // \u00A0 替换空格与制表符以保留对齐——二者均不依赖 white-space。用 createTextNode + // 而非 innerHTML,避免 stdout 内含