Skip to content

Commit 2460283

Browse files
committed
make deterministic cleanup code clearer
1 parent e7dc379 commit 2460283

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

webview-ui/src/services/mermaidSyntaxFixer.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff 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, "-->").replace(/```mermaid/, "")
30+
// surprisingly, this does most of the heavy lifting in fixing the Mermaid syntax
31+
cleanedCode = cleanedCode.replace(/-->/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(/^```mermaid/, "").replace(/```$/, "")
36+
37+
return cleanedCode
3138
}
3239

3340
/**

0 commit comments

Comments
 (0)