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.

Author

[Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui/)

md2star.preprocessing.mermaid.render_mermaid_local(content, out_dir)[source]

Render content (Mermaid markup) to a PNG and return its absolute path.

out_dir is accepted for backwards compatibility but the cache lives in $XDG_CACHE_HOME/md2star/mermaid/ so renders are shared across runs.

Parameters:
Return type:

str