diff --git a/desktop/src/components/chat/MermaidRenderer.test.tsx b/desktop/src/components/chat/MermaidRenderer.test.tsx index 5a4b835b..b95d30d3 100644 --- a/desktop/src/components/chat/MermaidRenderer.test.tsx +++ b/desktop/src/components/chat/MermaidRenderer.test.tsx @@ -78,6 +78,40 @@ describe('MermaidRenderer', () => { expect(arrow?.getAttribute('style') ?? '').not.toContain('stroke:') }) + it('quotes generated slash labels that Mermaid would parse as invalid shape syntax', async () => { + render( + D2[直接调用 dclService]', + ].join('\n')} + />, + ) + + await waitFor(() => { + expect(renderMock).toHaveBeenCalledWith( + expect.any(String), + [ + 'flowchart TD', + ' D1["/api/dcl"] --> D2[直接调用 dclService]', + ].join('\n'), + ) + }) + }) + + it('preserves slash-delimited Mermaid flowchart shapes', async () => { + const code = [ + 'flowchart TD', + ' A[/Manual input/] --> B[OK]', + ].join('\n') + + render() + + await waitFor(() => { + expect(renderMock).toHaveBeenCalledWith(expect.any(String), code) + }) + }) + it('fits oversized diagrams inside the chat message surface', async () => { const originalClientWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'clientWidth') Object.defineProperty(HTMLElement.prototype, 'clientWidth', { diff --git a/desktop/src/components/chat/MermaidRenderer.tsx b/desktop/src/components/chat/MermaidRenderer.tsx index 4489b05c..1e32f9f0 100644 --- a/desktop/src/components/chat/MermaidRenderer.tsx +++ b/desktop/src/components/chat/MermaidRenderer.tsx @@ -60,8 +60,17 @@ function isQuotedFlowchartLabel(label: string) { ) } +function isSlashDelimitedFlowchartShape(label: string) { + const trimmed = label.trim() + return trimmed.length >= 2 && trimmed.startsWith('/') && trimmed.endsWith('/') +} + function shouldQuoteFlowchartLabel(label: string) { - return !isQuotedFlowchartLabel(label) && UNQUOTED_FLOWCHART_LABEL_UNSAFE.test(label) + return ( + !isQuotedFlowchartLabel(label) && + !isSlashDelimitedFlowchartShape(label) && + UNQUOTED_FLOWCHART_LABEL_UNSAFE.test(label) + ) } function escapeFlowchartLabel(label: string) { diff --git a/desktop/src/pages/ActivitySettings.tsx b/desktop/src/pages/ActivitySettings.tsx index 334e6925..b4536a4a 100644 --- a/desktop/src/pages/ActivitySettings.tsx +++ b/desktop/src/pages/ActivitySettings.tsx @@ -772,9 +772,9 @@ export function ActivitySettings() { style={{ animationDelay: `${index * 45}ms` }} >
-
+ }`}> {metric.value}