pull/21281/head
xuzijie1995 11 months ago
parent cb8d0e81f2
commit 047db5f4bf

@ -30,10 +30,11 @@ export const prepareMermaidCode = (mermaidCode: string, style: 'classic' | 'hand
.replace(/^flowchart/, 'graph') .replace(/^flowchart/, 'graph')
.replace(/class="[^"]*"/g, '') .replace(/class="[^"]*"/g, '')
.replace(/fill="[^"]*"/g, '') .replace(/fill="[^"]*"/g, '')
.replace(/stroke="[^"]*"/g, ''); .replace(/stroke="[^"]*"/g, '')
// Ensure hand-drawn style charts always start with graph
if (!finalCode.startsWith('graph') && !finalCode.startsWith('flowchart')) if (!finalCode.startsWith('graph') && !finalCode.startsWith('flowchart'))
finalCode = `graph TD\n${finalCode}`; finalCode = `graph TD\n${finalCode}`
} }
return finalCode return finalCode
@ -163,7 +164,7 @@ export function isMermaidCodeComplete(code: string): boolean {
// The balanced bracket check was too strict and produced false negatives for valid // The balanced bracket check was too strict and produced false negatives for valid
// mermaid syntax like the asymmetric shape `A>B]`. Relying on Mermaid's own // mermaid syntax like the asymmetric shape `A>B]`. Relying on Mermaid's own
// parser is more robust. // parser is more robust.
const isBalanced = true; const isBalanced = true
// Check for common syntax errors // Check for common syntax errors
const hasNoSyntaxErrors = !trimmedCode.includes('undefined') const hasNoSyntaxErrors = !trimmedCode.includes('undefined')

Loading…
Cancel
Save