All files / src/meridian-mermaid polish-svg.ts

91.66% Statements 22/24
70% Branches 7/10
100% Functions 7/7
91.66% Lines 22/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Post-process Mermaid SVG output for Meridian viewer (no DOM required).
 */
 
export function polishMeridianSvg(svg: string): string {
  let out = svg.trim()
  if (!out) {
    return out
  }
 
  if (!/\bclass="[^"]*meridian-diagram/.test(out)) {
    out = out.replace(/<svg\b/, '<svg class="meridian-diagram"')
  }
 
  // Mermaid often sets max-width:100% — we handle sizing via pan/zoom viewport.
  out = out.replace(/\sstyle="max-width:\s*100%;?"/gi, "")
  out = out.replace(/\smax-width="[^"]*"/gi, "")
 
  if (!/role="img"/.test(out)) {
    out = out.replace(/<svg\b/, '<svg role="img"')
  }
 
  return out
}