From a60c04b53dd6589df0c027958149bd28a6a9099f Mon Sep 17 00:00:00 2001 From: Suzumiya Date: Tue, 15 Sep 2026 15:29:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=B9=E8=AF=9D=20markdown?= =?UTF-8?q?=20=E6=97=A0=E5=BA=8F=E5=88=97=E8=A1=A8=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ChatMarkdownMessage:无序列表改用真正的列表标记(list-disc + pl-4),不再手写 '- ' 文本前缀 - ChatMarkdownMessage:删除列表项里手写的短横线,换行后的第二行恢复悬挂缩进,同时恢复列表语义 - ChatMarkdownMessage:移除随之无用的 ListKindContext - ChatMarkdownMessage.test.tsx:用例改为断言 list-disc/pl-4 与「列表项文本不含手写短横线」 - 实测:真实面板注入同 class 标记后 list-style-type=disc、li 为 list-item、换行行与首行文字左边缘对齐 --- .../components/ChatMarkdownMessage/index.tsx | 31 +++++++------------ .../tests/ChatMarkdownMessage.test.tsx | 16 +++++++--- 2 files changed, 23 insertions(+), 24 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 3d79df338..81d852447 100644 --- a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx +++ b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx @@ -66,7 +66,6 @@ export class MarkdownErrorBoundary extends Component< } const ListDepthContext = createContext(0); -const ListKindContext = createContext<'unordered' | 'ordered' | null>(null); type ListItemParagraphPosition = 'first' | 'continuation'; const ListItemContext = createContext(null); @@ -75,15 +74,11 @@ function MarkdownUnorderedList({ children }: { children?: ReactNode }) { const depth = useContext(ListDepthContext); return ( - -
    0 ? 'pl-4' : 'pl-0' - }`} - > - {children} -
-
+ {/* 用真正的列表标记(`list-disc`)而不是手写 `'- '` 文本:手写前缀既没有悬挂缩进 + (换行后的第二行会顶回最左边),也不算列表语义(读屏读成普通文本)。 */} +
    + {children} +
); } @@ -98,14 +93,12 @@ function MarkdownOrderedList({ const depth = useContext(ListDepthContext); return ( - -
    - {children} -
-
+
    + {children} +
); } @@ -145,7 +138,6 @@ function StreamingMarkdownParagraph({ children }: { children?: ReactNode }) { } function MarkdownListItem({ children }: { children?: ReactNode }) { - const listKind = useContext(ListKindContext); let paragraphIndex = 0; const childrenWithParagraphContext = Children.map( children, @@ -168,7 +160,6 @@ function MarkdownListItem({ children }: { children?: ReactNode }) { ); return (
  • - {listKind === 'unordered' ? '- ' : null} {childrenWithParagraphContext}
  • ); diff --git a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx index 6df7c4333..cd3a150bd 100644 --- a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx +++ b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx @@ -31,7 +31,7 @@ describe('ChatMarkdownMessage', () => { ); }); - it('为嵌套无序列表保留逐层缩进', () => { + it('无序列表用真正的列表标记并逐层缩进,不再手写短横线', () => { const { container } = render( { const lists = container.querySelectorAll('ul'); expect(lists).toHaveLength(3); - expect(lists[0]?.className).toContain('pl-0'); - expect(lists[1]?.className).toContain('pl-4'); - expect(lists[2]?.className).toContain('pl-4'); + // 真正的列表标记:靠 `list-disc` 画项目符号、`pl-4` 让换行后的第二行保持悬挂缩进。 + for (const list of Array.from(lists)) { + expect(list.className).toContain('list-disc'); + expect(list.className).toContain('pl-4'); + expect(list.className).not.toContain('list-none'); + } + // 列表项文本里不能再出现手写的 `- ` 前缀(那会让换行行顶回最左边,也不符合列表语义)。 + for (const item of Array.from(container.querySelectorAll('ul > li'))) { + expect(item.textContent ?? '').not.toMatch(/^\s*-\s/); + } + expect(container.querySelector('ul > li')?.textContent).toBe('无序号 A'); }); it('为四到六级标题提供递进的字号与字重', () => {