Getting started

edit

Install the package

Add the Meziantou.Framework.Mermaid package to a project:

dotnet package add Meziantou.Framework.Mermaid

The types are in the Meziantou.Framework.Mermaid namespace.

Read and draw a diagram

MermaidDocument.Parse reads a text and returns its Content. Cast it to the type of the diagram, such as FlowchartDiagram, to read or change it, and write it as SVG:

var text = """
    ---
    title: Order processing
    config:
      theme: forest
    ---
    flowchart LR
        start([Order received]) --> check{Payment valid?}
        check -->|yes| ship[Ship the order]
        check -->|no| cancel[Cancel the order]
    """;

var document = MermaidDocument.Parse(text);
var flowchart = (FlowchartDiagram)document.Content;
var svg = flowchart.ToSvg();

To draw it as PNG, WebP or JPEG, see image rendering.

Write Mermaid text

MermaidWriter.Write writes a diagram as Mermaid text, which Mermaid and the parser read back:

var flowchart = new FlowchartDiagram { Direction = DiagramDirection.LeftToRight };
var start = flowchart.AddNode("start", "Start", FlowchartNodeShape.Stadium);
var end = flowchart.AddNode("end_node", "End", FlowchartNodeShape.DoubleCircle);
flowchart.AddEdge(start, end, "done").LineStyle = FlowchartLineStyle.Dotted;

var text = MermaidWriter.Write(flowchart);

See reading and writing for the errors, the warnings and what the writer cannot express.