Runtime API
The runtime layer turns wrapper HTML into an interactive diagram shell
Entry points
initMermaidIt(root?)
Finds unrendered wrappers and mounts them
ts
import { initMermaidIt } from 'markdown-it-mermaid-enhanced/runtime'
await initMermaidIt(document.querySelector('#app')!)rerenderMermaidIt(root?)
Rereads config and source from existing wrappers, then rerenders them in place
ts
import { rerenderMermaidIt } from 'markdown-it-mermaid-enhanced/runtime'
await rerenderMermaidIt(document.querySelector('#app')!)initWrapper(wrapper)
Mounts or rerenders one wrapper directly. This is mainly useful in host integrations with custom wrapper lifecycles
Export helpers
The runtime module also exports lower-level helpers
| Function | Purpose |
|---|---|
downloadSvg | Saves the current SVG |
downloadPng | Rasterizes and saves PNG |
copyToClipboard | Copies diagram source |
toggleFullscreen | Uses the browser fullscreen API |
convertMermaidToExcalidraw | Runs Mermaid to Excalidraw conversion directly |
createPanZoom | Creates the pan and zoom controller |
Runtime behavior notes
- Mounted wrappers are cached and reused
- Detached wrappers are cleaned up automatically
- Config-only refreshes rerender in place and preserve the mounted SVG node
- Zoom state survives config-only refreshes in the current runtime model