@streamdown/mermaid plugin renders Mermaid diagrams from fenced code blocks. Any code block tagged ```mermaid is rendered as an interactive SVG with fullscreen, download, copy, and pan/zoom controls.
Installation
Writing diagrams
Use a fenced code block with themermaid identifier:
Supported diagram types
Flowcharts
Visualize processes and workflows with
graph TD, graph LR, and other direction variants.Sequence diagrams
Model actor interactions with
sequenceDiagram.State diagrams
Represent state machines with
stateDiagram-v2.Class diagrams
Document object-oriented designs with
classDiagram.ER diagrams
Model database schemas with
erDiagram.Gantt charts
Plan project timelines with
gantt.Pie charts
Display proportional data with
pie.Git graphs
Visualize Git workflows with
gitGraph.MermaidOptions
Themermaid prop on <Streamdown> controls runtime rendering options and is separate from plugins.mermaid (which provides the library instance).
Theme configuration
Pass aMermaidConfig object to mermaid.config:
default, dark, forest, neutral, base.
The plugin’s default configuration is:
Custom error component
When a diagram fails to parse, Streamdown renders a built-in error state. You can replace it with your own component:Interactive controls
Each rendered diagram includes a toolbar with controls:| Control | Description |
|---|---|
panZoom | Pan and zoom the diagram |
fullscreen | Open the diagram in a fullscreen overlay |
download | Download the diagram as an SVG file |
copy | Copy the diagram to the clipboard |
controls prop:
Plugin API
createMermaidPlugin(options?)
DiagramPlugin
getMermaid() returns the initialized Mermaid instance. Passing a config argument calls mermaid.initialize() with a merged configuration before returning.
MermaidInstance
Pre-configured instance
@streamdown/mermaid exports a pre-configured instance with default settings:
