Mermaid Diagrams

With 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

Turn on the feature flag

nuxt.config.ts
export default defineNuxtConfig({
  extends: ['@movk/nuxt-docs'],

  movkNuxtDocs: {
    mermaid: true
  }
})
If 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:

Loading diagram...
```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 mermaid and 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:

ai-chat.mmd
Loading diagram...
```mermaid [ai-chat.mmd]
sequenceDiagram
    ...
```

Diagram types

Class diagram

classDiagram shows types and inheritance:

Loading diagram...

State diagram

stateDiagram-v2 shows state transitions:

Loading diagram...

Pie chart

pie shows proportions:

Loading diagram...

Gantt chart

gantt shows schedules and milestones:

Loading diagram...

Entity relationship diagram

erDiagram shows entities and their relationships:

Loading diagram...
See the Mermaid docs for more diagram types and syntax.

Styling

Override slot classes under ui.prose.mermaid in app/app.config.ts:

app/app.config.ts
export default defineAppConfig({
  ui: {
    prose: {
      mermaid: {
        slots: {
          root: 'my-8 border-primary/40',
          diagram: 'bg-default p-6'
        }
      }
    }
  }
})

Default theme:

app/app.config.ts
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
codestring

图表代码

iconany

图标

filename string

文件名

ui Partial<{ root: string; header: string; filename: string; icon: string; toolbar: string; diagram: string; loading: string; error: string; }>

Changelog

No recent changes
Copyright © 2024 - 2026