Merge pull request #995 from zhbdesign/patch-25

修复mermaid渲染遗漏了 /(斜杠)
This commit is contained in:
程序员阿江-Relakkes 2026-07-09 20:45:39 +08:00 committed by GitHub
commit fd542e4a44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -58,6 +58,24 @@ describe('MermaidRenderer Mermaid integration', () => {
expect(surface.innerHTML).not.toContain('onerror')
})
it('auto-quotes flowchart labels containing forward slashes to avoid lexical errors', async () => {
render(
<MermaidRenderer
code={[
'flowchart TD',
' D1[/api/dcl] --> D2[直接调用 dclService]',
' D2 --> R[返回结果]',
].join('\n')}
/>,
)
const surface = await screen.findByTestId('mermaid-diagram-surface')
expect(surface).toHaveTextContent('/api/dcl')
expect(surface).toHaveTextContent('直接调用 dclService')
expect(screen.queryByText('Mermaid Error')).not.toBeInTheDocument()
})
it('renders generated flowchart labels with HTML breaks and structural characters', async () => {
render(
<MermaidRenderer

View File

@ -40,7 +40,7 @@ type MermaidThemeColors = {
const FLOWCHART_START = /^\s*(?:graph|flowchart)\b/i
const FLOWCHART_NODE_START = /^([A-Za-z][\w-]*)\[/
const UNQUOTED_FLOWCHART_LABEL_UNSAFE = /<br\s*\/?>|[{}[\]*]/i
const UNQUOTED_FLOWCHART_LABEL_UNSAFE = /<br\s*\/?>|[{}[\]*\/]/i
function isFlowchartDiagram(code: string) {
const firstMeaningfulLine = code