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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MarkView.Avalonia.Mermaid" Version="12.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MarkView.Avalonia.Mermaid" Version="12.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MarkView.Avalonia.Mermaid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MarkView.Avalonia.Mermaid --version 12.0.2
                    
#r "nuget: MarkView.Avalonia.Mermaid, 12.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MarkView.Avalonia.Mermaid@12.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MarkView.Avalonia.Mermaid&version=12.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MarkView.Avalonia.Mermaid&version=12.0.2
                    
Install as a Cake Tool

MarkView.Avalonia.Mermaid

NuGet Version NuGet Downloads Avalonia CI License

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:

  1. Source lines are extracted from the fenced block.
  2. MermaidRenderer.RenderSvg produces an SVG string with Mermaider's CSS custom properties.
  3. CSS variable references (var(--_text) etc.) are inlined with computed hex values so SkiaSharp can render the diagram.
  4. The SVG is loaded into an SvgImage and displayed in an Image control.
  5. MaxWidth is constrained to the ScrollViewer viewport 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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