Mermaid diagrams

Render Mermaid diagrams from fenced code blocks in Comark.

The comark/plugins/mermaid plugin renders Mermaid diagrams from ```mermaid code blocks. Diagrams render client-side via the <Mermaid> component exported alongside the plugin.

beautiful-mermaid is a peer dependency. Install it alongside Comark with npm install beautiful-mermaid.

Usage

import { parseMarkdown } from 'comark'
import mermaid from 'comark/plugins/mermaid'

const result = await parseMarkdown(content, {
  plugins: [mermaid()]
})

With framework components, pass both the plugin and the Mermaid renderer component:

<script setup lang="ts">
import { Markdown } from '@comark/vue'
import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'
</script>

<template>
  <Suspense>
    <Markdown
      :components="{ mermaid: Mermaid }"
      :plugins="[mermaid()]"
    >{{ content }}</Markdown>
  </Suspense>
</template>

Features

Diagram types

Supported diagram types include:

Flowchart

```mermaid
graph TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> A
```

Sequence diagram

```mermaid
sequenceDiagram
    Alice->>Bob: Hello Bob!
    Bob-->>Alice: Hello Alice!
```

Class diagram

```mermaid
classDiagram
    Animal <|-- Duck
    Animal <|-- Fish
    Animal : +int age
    Animal: +isMammal()
```

State diagram

```mermaid
stateDiagram-v2
    [*] --> Still
    Still --> Moving
    Moving --> Crash
    Crash --> [*]
```

Gantt chart

```mermaid
gantt
    title Project Timeline
    dateFormat YYYY-MM-DD
    section Planning
    Task 1 :a1, 2024-01-01, 30d
    Task 2 :after a1, 20d
```

Pie chart

```mermaid
pie title Pets
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 15
```

Git graph

```mermaid
gitGraph
    commit
    branch develop
    checkout develop
    commit
    checkout main
    merge develop
```

ER diagram

```mermaid
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE-ITEM : contains
```

See the Mermaid documentation for the syntax reference for each diagram type.

Code block attributes

Pass component props directly on the opening fence:

```mermaid {theme="dark" width="800px" height="600px"}
graph TD
    A --> B
```

API

mermaid(options?)

Returns a ComarkPlugin that marks ```mermaid code blocks for custom rendering.

Parameters:

  • options?: Optional MermaidConfig:

    • theme?: ThemeNames: Sets the theme attribute on every diagram node, passed as a prop to the <Mermaid> component
    • themeDark?: ThemeNames: Sets the theme-dark attribute, used in dark mode

Returns: ComarkPlugin

The plugin converts mermaid code blocks into AST nodes that the <Mermaid> component renders. Rendering requires passing Mermaid to the components prop of <Markdown> (see Usage).


Component props

Props accepted by the <Mermaid> component:

PropTypeDefaultDescription
contentstringrequiredThe Mermaid diagram source
themestringundefinedMermaid theme. Defaults to tokyo-light (tokyo-night in dark mode). See available themes
themeDarkstringundefinedTheme to use in dark mode
widthstring'100%'Container width
heightstring'auto'Container height
classstring''CSS classes for the container

Examples

Vue + Vite Mermaid

Runnable Vue and Vite example rendering multiple Mermaid diagram types.
© 2026 Vercel, Inc.