Mermaid Diagrams in React Markdown
A React and Vite app that renders Mermaid fenced code blocks in Markdown with the Comark mermaid plugin.
This example renders fenced mermaid code blocks as SVG diagrams in React and Vite using @comark/react/plugins/mermaid and beautiful-mermaid.
Features
- Parses fenced
mermaidcode blocks intoMermaidnodes with themermaidplugin. - Renders flowcharts, sequence diagrams, state diagrams, and class diagrams as SVG through the
MermaidReact component. - Accepts per-diagram theme, width, and height props in the fence info string.
Usage
Install the renderer and
beautiful-mermaidpeer dependency:npm install @comark/react beautiful-mermaidImport the
mermaidplugin andMermaidcomponent:import { MarkdownClient } from '@comark/react' import mermaid, { Mermaid } from '@comark/react/plugins/mermaid'Pass the plugin and component to
MarkdownClient:<MarkdownClient value={content} components={{ Mermaid }} plugins={[mermaid()]} />Add a
mermaidcode block to your Markdown:```mermaid graph TD A[Start] --> B[End] ```
Theme support
Set a theme for an individual diagram in the fence attributes:
```mermaid {theme='zinc-dark'}
sequenceDiagram
participant A
participant B
A->>B: Hello
```