MCPcopy Create free account
hub / github.com/Effect-TS/effect / escapeMermaidLabel

Function escapeMermaidLabel

packages/effect/src/Graph.ts:3163–3181  ·  view source on GitHub ↗
(label: string)

Source from the content-addressed store, hash-verified

3161 * Escapes special characters in labels for Mermaid syntax compatibility.
3162 */
3163const escapeMermaidLabel = (label: string): string => {
3164 // Escape special characters for Mermaid using HTML entity codes
3165 // According to: https://mermaid.js.org/syntax/flowchart.html#special-characters-that-break-syntax
3166 return label
3167 .replace(/#/g, "#35;")
3168 .replace(/"/g, "#quot;")
3169 .replace(/</g, "#lt;")
3170 .replace(/>/g, "#gt;")
3171 .replace(/&/g, "#amp;")
3172 .replace(/\[/g, "#91;")
3173 .replace(/\]/g, "#93;")
3174 .replace(/\{/g, "#123;")
3175 .replace(/\}/g, "#125;")
3176 .replace(/\(/g, "#40;")
3177 .replace(/\)/g, "#41;")
3178 .replace(/\|/g, "#124;")
3179 .replace(/\\/g, "#92;")
3180 .replace(/\n/g, "<br/>")
3181}
3182
3183/**
3184 * Formats a Mermaid node with the specified shape and label.

Callers 1

Graph.tsFile · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected