Mermaid Diagrams
movkNuxtDocs.mermaid enabled and mermaid and dompurify installed, code blocks in the mermaid language render as flowcharts, sequence diagrams, class diagrams and more. Diagrams follow the color mode, load when scrolled into view and support copy and fullscreen.Enable
Mermaid is disabled by default.
Install the dependencies
pnpm add mermaid dompurify
npm install mermaid dompurify
yarn add mermaid dompurify
bun add mermaid dompurify
Turn on the feature flag
export default defineNuxtConfig({
extends: ['@movk/nuxt-docs'],
movkNuxtDocs: {
mermaid: true
}
})
mermaid is enabled without the dependencies installed, the build fails and the error lists the packages to install. When it is disabled, mermaid blocks are shown as plain code.Usage
Write a diagram in a code block with the mermaid language:
```mermaid
flowchart LR
A[Write Markdown] --> B{Has MDC components?}
B -->|Yes| C[Render Vue components]
B -->|No| D[Render prose elements]
C --> E[Output page]
D --> E
```
- Switches the Mermaid theme with the site's color mode
- Loads
mermaidand renders only once the diagram enters the viewport - Sanitizes the output with DOMPurify and runs Mermaid with
securityLevel: 'strict' - Shows copy and fullscreen buttons in the top-right corner on hover
Filename
As with regular code blocks, put a filename in square brackets to show it above the diagram:
```mermaid [ai-chat.mmd]
sequenceDiagram
...
```
Diagram types
Class diagram
classDiagram shows types and inheritance:
State diagram
stateDiagram-v2 shows state transitions:
Pie chart
pie shows proportions:
Gantt chart
gantt shows schedules and milestones:
Entity relationship diagram
erDiagram shows entities and their relationships:
Styling
Override slot classes under ui.prose.mermaid in app/app.config.ts:
export default defineAppConfig({
ui: {
prose: {
mermaid: {
slots: {
root: 'my-8 border-primary/40',
diagram: 'bg-default p-6'
}
}
}
}
})
Default theme:
export default defineAppConfig({
ui: {
prose: {
mermaid: {
slots: {
root: 'relative my-5 group border border-muted rounded-md overflow-hidden',
header: 'flex items-center gap-1.5 border-b border-muted bg-default px-4 py-3',
filename: 'text-default text-sm/6',
icon: 'size-4 shrink-0',
toolbar: 'absolute top-2 right-2 flex gap-1 z-10 opacity-0 group-hover:opacity-100 transition-opacity',
diagram: 'p-4 flex justify-center bg-elevated overflow-x-auto',
loading: 'p-4 flex items-center justify-center gap-2 text-sm text-muted',
error: 'p-4 flex items-center justify-center gap-2 text-sm text-error bg-error/10'
},
variants: {
fullscreen: {
true: {
root: 'fixed inset-0 z-50 m-0 rounded-none bg-default flex flex-col',
diagram: 'flex-1 overflow-auto',
toolbar: 'opacity-100'
}
}
}
}
}
}
})
API
Props
| Prop | Default | Type |
|---|---|---|
code | string图表代码 | |
icon | any图标 | |
filename | string文件名 | |
ui | Partial<{ root: string; header: string; filename: string; icon: string; toolbar: string; diagram: string; loading: string; error: string; }> |
Changelog
Images and Video
Insert remote or local images with Markdown image syntax, provide separate light and dark screenshots with `u-color-mode-image`, and embed videos with `:video`. Also covers where to put images and how to write alt text.
Content Components
Content components the layer adds on top of Nuxt UI prose. Motion adds entrance animations, StarsBg lays an animated star field behind a section, and LandingCover, LandingSection and friends build an editorial landing page. All work directly in Markdown.