md2star.preprocessing.mermaid module
Local Mermaid diagram rendering via the official Mermaid CLI (mmdc).
Uses npx -y @mermaid-js/mermaid-cli so no global install is required. The
rendered PNG is cached in the XDG cache directory keyed by MD5 of the source
plus the resolved body font (so re-skinning the template invalidates the
cache).
Requires Node.js ≥16 on PATH. Raises RuntimeError on failure so
the caller can decide whether to fall back to the original code block.
Box-overflow fix
Headless mmdc cannot measure HTML <foreignObject> text reliably, which is the
usual cause of “the words don’t fit inside the box”. The shipped
mermaid-config.json disables htmlLabels (forcing native SVG text that
auto-sizes) and bumps node padding. On top of that, this module reads the
active DOCX template’s body font (Normal style) and substitutes it into
the mermaid theme so diagrams visually match the surrounding prose.