From c58fee23b261b5c532144ad6ed3ee6f3ef4527a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 4 Sep 2026 12:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9B=B4=E6=A0=8F=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将包含换行的无语言围栏内容识别为代码块。 新增回归测试,确保其使用块级代码样式而非内联样式。 --- .../src/components/ChatMarkdownMessage/index.tsx | 4 +++- .../tests/ChatMarkdownMessage.test.tsx | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx index 8e2545024..8edc680a9 100644 --- a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx +++ b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx @@ -80,7 +80,9 @@ const markdownComponents: Components = { ), code: ({ className, children, node: _node, ...props }) => { - const isBlock = Boolean(className?.includes('language-')); + const isBlock = + Boolean(className?.includes('language-')) || + String(children).includes('\n'); return isBlock ? ( {children} diff --git a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx index 1c293be74..d37929a32 100644 --- a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx +++ b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx @@ -34,6 +34,19 @@ describe('ChatMarkdownMessage', () => { ).toBeNull(); }); + it('无语言标记的多行围栏代码仍使用代码块样式', () => { + const { container } = render( + , + ); + + const code = container.querySelector('pre code'); + expect(code?.className).toContain('whitespace-pre'); + expect(code?.className).not.toContain('rounded'); + }); + it('保留流式 assistant 文本并标记 streaming 状态', () => { const { container } = render(