# Load Mermaid Diagrams

## Content

**MermaidJS graph parsing** in **FlexDiagram** enables creating and rendering diagrams using **MermaidJS syntax**, a widely used text-based diagramming language. This feature allows importing MermaidJS text definitions, quickly prototyping diagrams, or converting existing text-based diagrams into FlexDiagram visuals.

>type=note
> Note: FlexDiagram supports basic MermaidJS flowchart features. Advanced MermaidJS features may not be supported.

![](https://cdn.mescius.io/document-site-files/images/ba3667c3-8434-4d44-931a-224dda3ad70f/MermaidjsFlexdiagram.fa4473.png?width=700)

### Create MermaidJS FlexDiagram

1. <span id="65e6bc33-86a4-4b95-86c4-30286ddd7ed0" annotationtype="inlineComment" data-mark-type="annotation" data-mark-annotation-type="inlineComment" data-id="65e6bc33-86a4-4b95-86c4-30286ddd7ed0" data-prosemirror-content-type="mark" data-prosemirror-mark-name="annotation">Create a text file or string that contains MermaidJS flowchart syntax.</span>

```auto
flowchart TD
    A(("Start 🍽️")) --> B["Gather Ingredients 🍅🧀🍞"]
    B --> C["Prepare Dough 🍞"]
    C --> D["Add Sauce 🍅"]
    D --> E{"Choose Toppings 🤔"}
    E -->|Cheese 🧀| F["Add Cheese 🧀"]
    E -->|Veggies 🥦🍄| G["Add Vegetables 🥦🍄"]
    E -->|Meat 🍖| H["Add Meat 🍖"]
    F --> I["Bake in Oven 🔥"]
    G --> I
    H --> I
    I --> J["Slice & Enjoy 😋🍕"]
    J --> K(("End ✅"))
    classDef default font-family:Segoe UI Emoji,font-size:16px;
```

 2\. Call the <span class="code" spellcheck="false" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code">LoadMermaidGraph()</span> method with the MermaidJS text and add the following code, ensuring that the <span class="code" spellcheck="false" data-prosemirror-content-type="mark" data-prosemirror-mark-name="code">C1.Diagram.Parser</span> namespace is referenced.

```auto
// Read text from the file
var text = File.ReadAllText(@"Resources\pizza.txt");
// Load Mermaid.js graph to the diagram
// https://mermaid.js.org/syntax/flowchart.html
diagram.LoadMermaidGraph(text);
```

>type=info
> Tip: MermaidJS content can also be loaded from a string variable instead of a file
>
> ```auto
> string mermaidText = @"
> flowchart LR
>     A[Start] --> B[Process]
>     B --> C[End]
> ";
> 
> diagram.LoadMermaidGraph(mermaidText);
> ```

#### **MermaidJS <span id="0af5ac8e-983f-467e-83d4-f6f657c2d7c9" annotationtype="inlineComment" data-mark-type="annotation" data-mark-annotation-type="inlineComment" data-id="0af5ac8e-983f-467e-83d4-f6f657c2d7c9" data-prosemirror-content-type="mark" data-prosemirror-mark-name="annotation">FlexDiagram Sample</span>**

```auto
using C1.Diagram.Parser;  // Required for LoadMermaidGraph
using C1.Win.Diagram;

namespace FlexDiagramPoC
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitializeDiagram();
        }
        
        private void InitializeDiagram()
        {
            // Create FlexDiagram instance
            var diagram = new FlexDiagram();
            diagram.Dock = DockStyle.Fill;
            Controls.Add(diagram);
            
            // Read text from the file
            var text = File.ReadAllText(@"Resources\pizza.txt");
            
            // Load Mermaid.js graph to the diagram
            // https://mermaid.js.org/syntax/flowchart.html
            diagram.LoadMermaidGraph(text);
        }
    }
}
```