.NET · no JavaScript · AOT-safe

Mermaid diagrams
in pure .NET.

Fast, low-allocation rendering with a normalized design language, themeable CSS variables, and allowlist SVG sanitization — no JavaScript runtime, no headless browser, no subprocess.

nuget ↗
usage
string svg = MermaidRenderer.RenderSvg("""
    flowchart LR
      A[Parse] --> B[Layout]
      B --> C[Render SVG]
""");
// drop svg directly into your HTML
Rendered flowchart

Everything Mermaid.
Zero JavaScript.

Mermaider parses Mermaid diagram syntax and renders it directly to SVG in-process — no interop, no spawned process, no browser dependency.

no javascript
Pure .NET

Built entirely in C#. No JS runtime dependency, no Puppeteer, no Node subprocess. Ships as a NuGet package that targets net8.0+.

flowchart · sequence · class · er · …
All major
diagram types

Flowchart, sequence, class, ER, state, architecture, C4, gitgraph, gantt, pie, mindmap, and more — the full Mermaid feature surface.

zero allocation
Built for
throughput

ObjectPool<StringBuilder> for SVG assembly, ReadOnlySpan<char> throughout the text pipeline, SIMD character lookups via SearchValues<char>.

xss-safe
Sanitized
by default

Every SVG output passes through an allowlist sanitizer before leaving the library. Strict mode strips all diagram-source styling, eliminating the injection surface entirely.

css custom properties
Themeable

Colors are CSS custom properties — override --bg, --fg, --accent to match any design system. Themes are computed at render time, no post-processing needed.

aot + trimming
AOT-ready

All regex patterns are source-generated with [GeneratedRegex]. No reflection-based dispatch. Trims cleanly and publishes as a native binary.


Purpose-built for
.NET servers.

Mermaider exists because every other option either requires a JavaScript runtime or produces inconsistent output across diagram types. These four properties are non-negotiable.

one token system · 24 types
Single design
language

Every diagram type — flowchart, sequence, class, ER, architecture, gantt, pie, and all the rest — renders using the same CSS custom-property token system. Set --bg, --fg, and --accent once; every diagram adapts. No per-type theme overrides, no inconsistent defaults slipping through.

allowlist · strict mode · resource limits
Safety by
default

Every SVG output passes through an allowlist sanitizer before it reaches the caller — no opt-in required. Strict mode removes all diagram-source styling from the stylesheet, so untrusted diagram authors cannot override your design system. Resource limits with a cooperative render deadline bound CPU and memory for arbitrary inputs. All regex patterns carry a 2-second timeout for ReDoS protection.

security docs →
3.4 µs · 16 KB · ObjectPool · spans · SIMD
Fast and
low-allocation

The SVG renderer pools StringBuilder instances via ObjectPool<StringBuilder> and never allocates one per render. The text pipeline operates on ReadOnlySpan<char> throughout; character-class lookups use SearchValues<char> for SIMD acceleration. Immutable lookup tables are FrozenDictionary. A 6-node flowchart completes in 3.4 µs and allocates 16 KB — 73× faster than MSAGL, 35× fewer allocations.

O(V+E) · rectilinear routing · CSR adjacency
Own Sugiyama
layout engine

Mermaider ships a complete, zero-dependency Sugiyama implementation: cycle removal, longest-path layering, barycenter crossing minimization, coordinate assignment, and rectilinear edge routing with rounded corners and shared trunk segments. All three historically O(N³) phases were rewritten using a CSR adjacency index and now run in O(V+E). The engine is also published as a standalone Sugiyama NuGet package.

layout docs →


One package.
Then pass a string.

One NuGet reference. No configuration files, no external processes, no runtime setup. One call to RenderSvg, one SVG string back.

01
Add the package

dotnet add package Mermaider — targets net8.0 and later. No transitive JS or native dependencies.

02
Create a renderer

Construct a MermaidRenderer, optionally passing RenderOptions to configure colors, strict mode, or resource limits. The renderer is thread-safe and designed to be shared.

03
Embed the SVG

The returned string is a complete, sanitized SVG. Write it directly into your HTML response — no file system, no temp files, no process to clean up.

basic usage
using Mermaider;

string svg = MermaidRenderer.RenderSvg("""
    graph TD
      A[Start] --> B{Check}
      B --> |yes| C[Done]
      B --> |no|  D[Retry]
""");

// embed it directly in HTML
Response.Write(svg);
strict mode + theming
var options = new RenderOptions
{
    Bg = "#0D1117", Fg = "#E6EDF3",
    Strict = new StrictStylingOptions()
};

string svg = MermaidRenderer.RenderSvg(diagram, options);

One package.
Pure .NET.
Every diagram.

No runtime, no subprocess. Just a NuGet package that turns Mermaid syntax into production-ready SVG.