Mermaid Diagrams in Vue Markdown

A Vue and Vite app that renders Mermaid fenced code blocks in Markdown with the Comark mermaid plugin.
App.vue
<script setup lang="ts">
import { Comark } from '@comark/vue'
import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'

const markdown = `
# Mermaid Diagram Example

## Flowchart

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

## Sequence Diagram

\`\`\`mermaid {theme='zinc-dark'}
sequenceDiagram
    participant User
    participant App
    participant API
    User->>App: Request data
    App->>API: Fetch data
    API-->>App: Return data
    App-->>User: Display data
\`\`\`
`
</script>

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

This example renders fenced mermaid code blocks as SVG diagrams in Vue and Vite using @comark/vue/plugins/mermaid and beautiful-mermaid.

Features

  • Parses fenced mermaid code blocks into Mermaid nodes with the mermaid plugin.
  • Renders flowcharts, sequence diagrams, state diagrams, and class diagrams as SVG through the Mermaid Vue component.
  • Accepts per-diagram theme, width, and height props in the fence info string.

Usage

  1. Import the mermaid plugin and Mermaid component:

    import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'
  2. Pass the plugin and component to <Markdown>:

    <Suspense>
      <Markdown
        :plugins="[mermaid()]"
        :components="{ Mermaid }"
      >
        {{ content }}
      </Markdown>
    </Suspense>
  3. Add a mermaid code block to your Markdown:

    ```mermaid
    graph TD
        A[Start] --> B[End]
    ```

Learn more

© 2026 Vercel, Inc.