MarkView.Avalonia.Mermaid
12.1.1
dotnet add package MarkView.Avalonia.Mermaid --version 12.1.1
NuGet\Install-Package MarkView.Avalonia.Mermaid -Version 12.1.1
<PackageReference Include="MarkView.Avalonia.Mermaid" Version="12.1.1" />
<PackageVersion Include="MarkView.Avalonia.Mermaid" Version="12.1.1" />
<PackageReference Include="MarkView.Avalonia.Mermaid" />
paket add MarkView.Avalonia.Mermaid --version 12.1.1
#r "nuget: MarkView.Avalonia.Mermaid, 12.1.1"
#:package MarkView.Avalonia.Mermaid@12.1.1
#addin nuget:?package=MarkView.Avalonia.Mermaid&version=12.1.1
#tool nuget:?package=MarkView.Avalonia.Mermaid&version=12.1.1
MarkView.Avalonia.Mermaid
Mermaid diagram rendering extension for MarkView.Avalonia. Renders fenced mermaid code blocks as vector diagrams using Mermaider — a pure managed .NET parser and renderer. No browser, no WebView, and no JavaScript runtime required.
Installation
dotnet add package MarkView.Avalonia.Mermaid
Quick Start
Call UseMermaid() before setting Markdown:
var viewer = new MarkdownViewer();
viewer.UseMermaid();
viewer.Markdown = markdownText;
Or activate globally at application startup:
// App.axaml.cs
MarkdownViewerDefaults.Extensions.AddMermaid();
Diagrams are written in standard Mermaid syntax inside a fenced code block:
```mermaid
graph TD
A[Start] --> B{Decision}
B -- Yes --> C[End]
B -- No --> A
```
Supported Diagram Types
The extension targets the diagram types supported by the version of Mermaider this package depends on, including common diagrams such as:
- Flowcharts (
graph TD,flowchart LR) - Sequence diagrams (
sequenceDiagram) - Class diagrams (
classDiagram) - State diagrams (
stateDiagram-v2) - Entity-relationship diagrams (
erDiagram) - Gantt charts (
gantt) - Pie charts (
pie) - Git graphs (
gitGraph) - Mind maps (
mindmap) - Timeline (
timeline)
See the Mermaid documentation for syntax reference. If a diagram fails to render, the extension falls back to a plain-text block containing the original source.
Theme Awareness
Diagrams are rendered with colours matching the active Avalonia theme variant:
| Variant | Background | Foreground | Accent |
|---|---|---|---|
| Dark | #18181B |
#FAFAFA |
#60a5fa |
| Light | #FFFFFF |
#27272A |
#3b82f6 |
When the user switches between light and dark, the diagram is automatically re-rendered. The Border container stays in place — scroll position is preserved and other document elements are not affected.
Combining with Syntax Highlighting
When MarkView.Avalonia.SyntaxHighlighting is also registered, non-mermaid fenced code blocks in the same document get full syntax highlighting. Registration order does not matter:
// Per-instance
viewer
.UseTextMateHighlighting()
.UseMermaid();
// Or globally
MarkdownViewerDefaults.Extensions.AddTextMateHighlighting();
MarkdownViewerDefaults.Extensions.AddMermaid();
MermaidBlockRenderer handles all FencedCodeBlock nodes. Mermaid blocks are rendered as diagrams; all other fenced blocks are rendered as styled code blocks using any ICodeHighlighter registered by the SyntaxHighlighting extension.
How It Works
UseMermaid() registers a MermaidExtension which inserts MermaidBlockRenderer at index 0 of renderer.ObjectRenderers. Being first in the renderer list, it intercepts every FencedCodeBlock before the default CodeBlockRenderer.
For mermaid blocks:
- Source lines are extracted from the fenced block.
MermaidRenderer.RenderSvgproduces an SVG string with Mermaider's CSS custom properties.- CSS variable references (
var(--_text)etc.) are inlined with computed hex values so SkiaSharp can render the diagram. - The SVG is loaded into an
SvgImageand displayed in anImagecontrol. MaxWidthis constrained to theScrollViewerviewport and updated on resize.
For non-mermaid blocks, rendering is delegated to the standard code block path (with theme-aware in-place TextBlock.Inlines rebuild if a IThemeAwareCodeHighlighter is registered).
License
MIT © Nicolas Musset
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MarkView.Avalonia (>= 12.1.1)
- Mermaider (>= 0.12.2)
- Svg.Controls.Skia.Avalonia (>= 12.0.0.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 12.1.1 | 150 | 8/15/2026 | |
| 12.1.0 | 96 | 8/12/2026 | |
| 12.0.3 | 202 | 5/9/2026 | |
| 12.0.2 | 150 | 4/21/2026 | |
| 12.0.1 | 120 | 4/16/2026 | |
| 12.0.1-beta.3 | 113 | 4/15/2026 | |
| 12.0.1-beta.2 | 113 | 4/10/2026 |