Mermaid diagrams
Example showing how to use Comark with Mermaid diagrams in Vue and Vite.
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>
Features
This example demonstrates how to use Comark with Mermaid diagrams in Vue:
- Mermaid Plugin: Import and configure
@comark/mermaidplugin to parse mermaid code blocks - Mermaid Component: Register the
Mermaidcomponent to render diagrams as SVG - Multiple Diagram Types: Supports flowcharts, sequence diagrams, and all other Mermaid diagram types
- Configurable: Customize theme, width, and height via component props
Usage
- Import the mermaid plugin and component:
import mermaid from '@comark/mermaid' import { Mermaid } from '@comark/vue/plugins/mermaid/vue' - Pass the plugin to Comark:
<Comark :plugins="[mermaid()]" /> - Register the Mermaid component:
<Comark :components="{ mermaid: Mermaid }" /> - Use mermaid code blocks in your markdown:
```mermaid graph TD A[Start] --> B[End] ```