How it works
The package exists because raw Mermaid HTML is only the first half of the job. A real docs site still needs hydration, rerendering, export, zoom, fullscreen, and route-aware lifecycle control
The problem it solves
markdown-it turns a fence into HTML. It does not keep browser state, rerender on route changes, or provide a toolbar
markdown-it-mermaid-enhanced fills that gap in two stages
- The markdown-it plugin converts each Mermaid fence into a runtime-friendly wrapper
- The browser runtime upgrades that wrapper into an interactive diagram shell
The pipeline
Package architecture
This split keeps compile-time HTML generation browser-side interactivity shared config resolution and VitePress integration clearly separated
Rendering workflow
The key boundary is that the markdown-it side only serializes state while the runtime side owns async rendering and interaction state
What the plugin emits
Each diagram becomes a wrapper with three important parts
- A hidden
<pre>that stores the original Mermaid source - A
data-mermaid-configpayload that captures the resolved config - A toolbar with zoom, copy, export, and fullscreen actions
That wrapper format matters because rerendering reads from the same DOM node instead of replacing the whole block
Runtime model
The browser runtime upgrades wrappers into Vue apps on demand
initMermaidIt()finds unmounted wrappers and mounts them oncererenderMermaidIt()rereads wrapper state and rerenders in place- Pan and zoom state live beside the wrapper, so config-only updates can preserve the current viewport
Runtime design
Each wrapper keeps a small runtime state bag so rerenders can swap SVG content in place instead of destroying the host node
Why route changes need help
Single-page docs frameworks replace page content without reloading the browser runtime. That is why the VitePress integration waits for DOM updates, retries wrapper discovery, and then mounts new diagrams after navigation
Key source files
src/markdown-it/plugin.tshandles fences and wrapper HTMLsrc/runtime.tsexposes the public runtime entry pointssrc/runtime/MermaidWrapperRuntime.vueowns the interactive shellsrc/runtime/core.tshandles rendering, export, SVG mounting, and pan or zoomsrc/vitepress.tsadapts the runtime to VitePress route changes