Built-in

Mermaid Diagrams

Plugin for rendering Mermaid diagrams in Comark using code blocks.

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

beautiful-mermaid is a peer dependency — install it alongside Comark: npm install beautiful-mermaid

Usage

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

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

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

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

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

Features

Diagram Types

Mermaid supports a wide range of diagram types:

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 full syntax reference on 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()

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

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 <Comark> — see Usage.


Component Props

Props accepted by the <Mermaid> component:

PropTypeDefaultDescription
contentstringrequiredThe Mermaid diagram source
themestring'default'Mermaid theme — 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

Complete working implementation with multiple diagram types.