MarkView.Avalonia.Mermaid
12.0.2
dotnet add package MarkView.Avalonia.Mermaid --version 12.0.2
NuGet\Install-Package MarkView.Avalonia.Mermaid -Version 12.0.2
<PackageReference Include="MarkView.Avalonia.Mermaid" Version="12.0.2" />
<PackageVersion Include="MarkView.Avalonia.Mermaid" Version="12.0.2" />
<PackageReference Include="MarkView.Avalonia.Mermaid" />
paket add MarkView.Avalonia.Mermaid --version 12.0.2
#r "nuget: MarkView.Avalonia.Mermaid, 12.0.2"
#:package MarkView.Avalonia.Mermaid@12.0.2
#addin nuget:?package=MarkView.Avalonia.Mermaid&version=12.0.2
#tool nuget:?package=MarkView.Avalonia.Mermaid&version=12.0.2
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 referenced Mermaider version, 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.
Platform Notes
Mermaider renders diagrams in managed .NET code (no JavaScript runtime). If diagram rendering fails for any reason, this extension automatically falls back to a plain-text Border containing the original Mermaid source.
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.0.2)
- Mermaider (>= 0.6.0)
- Svg.Controls.Skia.Avalonia (>= 12.0.0.3)
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.0.2 | 103 | 4/21/2026 |
| 12.0.1 | 93 | 4/16/2026 |
| 12.0.1-beta.3 | 57 | 4/15/2026 |
| 12.0.1-beta.2 | 56 | 4/10/2026 |