From a8559597cade92b8ea90a30d8d96a2080be3abff Mon Sep 17 00:00:00 2001 From: Suzumiya Date: Tue, 15 Sep 2026 23:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=20Markdown=20=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 保留两个换行表示的正常空行,仅压缩普通正文中的连续多余换行 --- .../components/ChatMarkdownMessage/index.tsx | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) 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 90bf6f82d..ad2ebaa39 100644 --- a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx +++ b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx @@ -15,6 +15,16 @@ export type ChatMarkdownMessageProps = { streaming?: boolean; }; +/** 只压缩普通 Markdown 正文里多余的空行;代码块中的换行必须原样保留。 */ +function normalizeMarkdownBlankLines(text: string) { + return text + .split(/(```[\s\S]*?```)/g) + .map((part, index) => + index % 2 === 1 ? part : part.replace(/\n{3,}/g, '\n\n'), + ) + .join(''); +} + type MarkdownErrorBoundaryProps = { fallbackText: string; children: ReactNode; @@ -76,7 +86,7 @@ function MarkdownUnorderedList({ children }: { children?: ReactNode }) { {/* 用真正的列表标记(`list-disc`)而不是手写 `'- '` 文本:手写前缀既没有悬挂缩进 (换行后的第二行会顶回最左边),也不算列表语义(读屏读成普通文本)。 */} -