Prosefly

Guides

Mermaid Diagrams

Turn Mermaid code blocks into responsive, themed SVG diagrams at build time.

Write a fenced code block with the mermaid language and the shared proseflyComponents() integration turns it into a static SVG. The same syntax works in Markdown and MDX, requires no component import, and ships no Mermaid runtime to the browser.

Using a Prosefly theme

Dahlia and Lotus already register the shared integration. Mermaid diagrams work automatically in those projects.

Quick Start

Add title="..." after the language when the diagram needs a specific accessible name. Without it, the renderer derives a name from the diagram type.

Publishing flow Markdown Astro SVG

The transform runs during the Astro build. It replaces the code block with a responsive <figure> containing inline SVG, so the result appears immediately and continues to work when JavaScript is disabled.

Supported Diagram Types

Rendering is powered by beautiful-mermaid and supports a focused subset of Mermaid:

DiagramOpening declarationGood for
Flowchartflowchart LR or graph TDProcesses, decisions, and architecture
StatestateDiagram-v2Lifecycles and transitions
SequencesequenceDiagramRequests and interactions over time
ClassclassDiagramTypes, members, and relationships
Entity relationshiperDiagramData models and cardinality
XY chartxychart-betaBar, line, and combined charts

Flowchart

Flowcharts support top-down, left-right, bottom-top, and right-left directions, along with labels and common node shapes.

Content publishing decision Yes No Write draft Approved? Publish page

State Diagram

Use state diagrams when the important information is how one state changes into another.

Article lifecycle submit approve request changes Draft Review Published

Sequence Diagram

Sequence diagrams make request order and cache behavior visible without a long procedural explanation.

Cached metadata request alt [Cached] [Missing] Resolve URL Return metadata Fetch metadata Return response Return metadata Page Cache Provider

Class Diagram

Class diagrams support members, methods, annotations, inheritance, composition, aggregation, dependencies, and relationship labels.

Markdown rendering classes MarkdownPage + title: String + body: String + render(): String Diagram + source: String + toSVG(): String

Entity Relationship Diagram

Use an ER diagram to show entities and cardinality. Entity fields are optional when the relationships are the main point.

Documentation content model SITE (no attributes) PAGE string slug string title DIAGRAM string type string source contains renders

XY Chart

XY charts accept bar and line series. The accent token supplies the primary series color and the renderer derives additional series from it.

Documentation traffic by month Jan Feb Mar Apr May Jun 0 10 20 30 40 50 Visits (K) Documentation traffic Bar 1 Line 1

A focused Mermaid subset

Gantt charts, mindmaps, pie charts, user journeys, and C4 diagrams are not currently supported. Unsupported syntax fails the build instead of silently producing an empty or incomplete diagram.

Authoring Rules

  1. Use the exact mermaid language.

    Other language names remain normal code blocks.

  2. Add a short, descriptive title.

    Write title="Request lifecycle" on the opening fence. It becomes the SVG <title> referenced by aria-labelledby; it is not a visible caption.

  3. Use supported Mermaid syntax.

    beautiful-mermaid intentionally implements the six diagram families listed above, not the complete Mermaid grammar.

  4. Treat render failures as content errors.

    Invalid and unsupported diagrams stop the build. The error includes the source file and code-block line so the diagram can be fixed at its origin.

Theming

The generated SVG references the same CSS custom properties as the Astro components. It updates with the site’s light or dark theme without being rendered again.

TokenDiagram role
--pf-backgroundDiagram background and color calculations
--pf-textPrimary labels
--pf-text-mutedSecondary labels and annotations
--pf-surfaceNode surfaces
--pf-border-subtleNode and group borders
--pf-border-mutedConnectors
--pf-accentArrowheads and chart series
--pf-font-sansLabels and headings
--pf-font-monoMonospaced diagram text

Every token has a built-in fallback. Standalone sites can override the tokens in their layout; Prosefly themes already provide them.

Standalone Astro Setup

Register the shared integration once. Mermaid rendering is enabled by default, and the integration safely adds mermaid to the existing markdown.syntaxHighlight.excludeLangs list.

astro.config.ts
import { defineConfig } from 'astro/config';
import proseflyComponents from '@prosefly/astro-components/integration';
export default defineConfig({
integrations: [proseflyComponents()],
});

To keep the other shared Markdown transforms but disable Mermaid rendering:

astro.config.ts
proseflyComponents({
markdown: { mermaid: false },
});

Advanced Processor Setup

Use the public rehypeMermaid plugin when composing the Markdown processor yourself. Manual setups must also exclude mermaid from syntax highlighting so the plugin receives the original code block.

astro.config.ts
import { defineConfig } from 'astro/config';
import {
rehypeMermaid,
unified,
} from '@prosefly/astro-components/markdown';
export default defineConfig({
markdown: {
syntaxHighlight: {
type: 'shiki',
excludeLangs: ['math', 'mermaid'],
},
processor: unified({
rehypePlugins: [rehypeMermaid],
}),
},
});

Last updated Sep 10, 2026