File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,17 @@ export class MermaidSyntaxFixer {
2424 * Applies deterministic fixes for common LLM errors before validation
2525 */
2626 static applyDeterministicFixes ( code : string ) : string {
27+ let cleanedCode = code // use variable to be able to add comments to each step
28+
2729 // Fix HTML entity encoding: --> should be -->;
28- // surprisingly, this does most of the heavy lifting in the MermaidSyntaxFixer
29- // sometimes the llm prepends ```mermaid, remove that
30- return code . replace ( / - - & g t ; / g, "-->" ) . replace ( / ` ` ` m e r m a i d / , "" )
30+ // surprisingly, this does most of the heavy lifting in fixing the Mermaid syntax
31+ cleanedCode = cleanedCode . replace ( / - - & g t ; / g, "-->" )
32+
33+ // sometimes the llm wraps the respond in a code block, starting with ```mermaid and ending with ```
34+ // we remove those to get the actual code
35+ cleanedCode = cleanedCode . replace ( / ^ ` ` ` m e r m a i d / , "" ) . replace ( / ` ` ` $ / , "" )
36+
37+ return cleanedCode
3138 }
3239
3340 /**
You can’t perform that action at this time.
0 commit comments