@comark/plugin-beautiful-mermaid

Mermaid plugin for Comark. Renders fenced ```mermaid blocks as diagrams with beautiful-mermaid, in HTML, terminal, Vue, React, Svelte and Angular.
Features
beautiful-mermaid ships as a dependency, so there is nothing else to install
- Diagrams render to inline SVG, or to ASCII in the terminal
- Component props on the opening fence, such as
{.class} and {theme="nord"}
- Light and dark themes, following the
<html> element's dark class
Mermaid components for Vue, React, Svelte, Angular, HTML and ANSI
- Full TypeScript support
Installation
npm install @comark/plugin-beautiful-mermaid
# or
pnpm add @comark/plugin-beautiful-mermaid
Usage
import { parseMarkdown } from 'comark'
import mermaid from '@comark/plugin-beautiful-mermaid'
const result = await parseMarkdown('```mermaid\ngraph TD; A-->B;\n```', {
plugins: [mermaid()],
})
The plugin stores the diagram source in the node. Rendering needs a Mermaid component:
<script setup lang="ts">
import { Markdown } from '@comark/vue'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/vue'
</script>
<template>
<Markdown :plugins="[mermaid()]" :components="{ mermaid: Mermaid }">{{ content }}</Markdown>
</template>
import { Markdown } from '@comark/react'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/react'
<Markdown plugins={[mermaid()]} components={{ mermaid: Mermaid }}>{content}</Markdown>
<script lang="ts">
import { Markdown } from '@comark/svelte'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/svelte'
</script>
<Markdown {content} plugins={[mermaid()]} components={{ mermaid: Mermaid }} />
Each component entry exports only its component, so the plugin always comes from the package root. The Angular adapter (@comark/plugin-beautiful-mermaid/angular) and the HTML and ANSI render functions (@comark/plugin-beautiful-mermaid/html, @comark/plugin-beautiful-mermaid/ansi) follow the same rule.
API
mermaid(options?) returns the plugin. Options: theme and themeDark set the theme on every diagram node.
Mermaid components are exported from ./vue, ./react, ./svelte, ./angular, ./html and ./ansi.
Documentation
Full guide and API reference at comark.dev/plugins/official/beautiful-mermaid.
License
Made with ❤️
Published under MIT License.