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
mermaidcode blocks intoMermaidnodes with themermaidplugin. - Renders flowcharts, sequence diagrams, state diagrams, and class diagrams as SVG through the
MermaidVue component. - Accepts per-diagram theme, width, and height props in the fence info string.
Usage
Import the
mermaidplugin andMermaidcomponent:import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'Pass the plugin and component to
<Markdown>:<Suspense> <Markdown :plugins="[mermaid()]" :components="{ Mermaid }" > {{ content }} </Markdown> </Suspense>Add a
mermaidcode block to your Markdown:```mermaid graph TD A[Start] --> B[End] ```