修复无语言代码围栏样式

将包含换行的无语言围栏内容识别为代码块。

新增回归测试,确保其使用块级代码样式而非内联样式。
This commit is contained in:
2026-09-04 12:55:41 +08:00
parent da3033db21
commit c58fee23b2
2 changed files with 16 additions and 1 deletions
@@ -80,7 +80,9 @@ const markdownComponents: Components = {
</pre>
),
code: ({ className, children, node: _node, ...props }) => {
const isBlock = Boolean(className?.includes('language-'));
const isBlock =
Boolean(className?.includes('language-')) ||
String(children).includes('\n');
return isBlock ? (
<code {...props} className="font-mono whitespace-pre">
{children}
@@ -34,6 +34,19 @@ describe('ChatMarkdownMessage', () => {
).toBeNull();
});
it('无语言标记的多行围栏代码仍使用代码块样式', () => {
const { container } = render(
<ChatMarkdownMessage
role="assistant"
text={'```\nconst answer = 42;\nreturn answer;\n```'}
/>,
);
const code = container.querySelector('pre code');
expect(code?.className).toContain('whitespace-pre');
expect(code?.className).not.toContain('rounded');
});
it('保留流式 assistant 文本并标记 streaming 状态', () => {
const { container } = render(
<ChatMarkdownMessage