Skip to content

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

FunctionPurpose
downloadSvgSaves the current SVG
downloadPngRasterizes and saves PNG
copyToClipboardCopies diagram source
toggleFullscreenUses the browser fullscreen API
convertMermaidToExcalidrawRuns Mermaid to Excalidraw conversion directly
createPanZoomCreates 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