Mermaid with Native Markdown Syntax

By Amr

Simple Mermaid diagrams using native markdown code blocks via jekyll-mermaid

Estimated reading time: 4 minutes

Mermaid with Native Markdown Syntax

✨ Simple Implementation: No HTML tags needed! Just use markdown code blocks.


πŸš€ Quick Start

Step 1: Write Markdown Code Blocks

Simply use triple backticks with mermaid as the language:

```mermaid
graph TD
    A[Start] --> B[End]
```

Step 2: That’s It!

No front matter needed, no HTML <div> tags, just pure markdown.


πŸ“Š Examples

Example 1: Basic Flowchart

```mermaid
graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[Car]
```

Result:

graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[Car]

Example 2: Sequence Diagram

```mermaid
sequenceDiagram
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
    Alice-)John: See you later!
```

Result:

sequenceDiagram
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
    Alice-)John: See you later!

Example 3: Class Diagram

```mermaid
classDiagram
    Animal <|-- Duck
    Animal <|-- Fish
    Animal : +int age
    Animal : +String gender
    Animal: +isMammal()
    class Duck{
        +String beakColor
        +swim()
        +quack()
    }
```

Result:

classDiagram
    Animal <|-- Duck
    Animal <|-- Fish
    Animal : +int age
    Animal : +String gender
    Animal: +isMammal()
    class Duck{
        +String beakColor
        +swim()
        +quack()
    }

Example 4: State Diagram

```mermaid
stateDiagram-v2
    [*] --> Still
    Still --> [*]
    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
```

Result:

stateDiagram-v2
    [*] --> Still
    Still --> [*]
    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]

Example 5: Gantt Chart

```mermaid
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2025-01-01, 30d
    Another task     :after a1  , 20d
```

Result:

gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2025-01-01, 30d
    Another task     :after a1  , 20d

Example 6: Pie Chart

```mermaid
pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 15
```

Result:

pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 15

🎯 Benefits

βœ… Simpler Syntax

  • Before: <div class="mermaid">graph TD...</div> + mermaid: true in front matter
  • After: Just ` mermaid ... ` in markdown

βœ… Standard Markdown

  • Native markdown code block syntax
  • Compatible with other markdown processors
  • GitHub-style fenced code blocks

βœ… No Configuration Needed

  • No front matter variables required
  • No conditional includes
  • Just write and it works

βœ… Cleaner Content

  • Pure markdown syntax
  • No HTML mixed in
  • Easier to read and edit

πŸ“š All Supported Diagram Types

Type Syntax Description
Flowchart graph TD Process flows and decisions
Sequence sequenceDiagram System interactions
Class classDiagram OOP relationships
State stateDiagram-v2 State machines
ER erDiagram Database schemas
Gantt gantt Project timelines
Pie pie Data percentages
Git gitGraph Version control flows
Journey journey User experiences

πŸ”§ Configuration

The plugin is configured in _config.yml:

plugins:
  - jekyll-mermaid

mermaid:
  src: 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js'

That’s all the configuration needed!


πŸ“ Usage Summary

In Your Markdown Files

Just use standard markdown code blocks:

```mermaid
graph LR
    A --> B --> C
```

No Front Matter Needed

Unlike the previous implementation, you don’t need:

---
mermaid: true  # ← NOT NEEDED ANYMORE
---

No HTML Tags Needed

Unlike the previous implementation, you don’t need:

<div class="mermaid">  <!-- ← NOT NEEDED ANYMORE -->
graph LR
    A --> B
</div>

πŸŽ“ Quick Reference

Flowchart Directions

TD or TB - Top to bottom
BT - Bottom to top
LR - Left to right
RL - Right to left

Node Shapes

[Rectangle]
(Rounded)
{Diamond}
((Circle))
>Flag]

Arrow Types

-->  Solid arrow
-.-> Dotted arrow
==>  Thick arrow
--   Line without arrow

πŸ”— Resources


✨ Advantages of This Approach

  1. Native Markdown - Standard fenced code blocks
  2. Simpler - No HTML, no front matter variables
  3. Portable - Works with other markdown processors
  4. Cleaner - Easier to read and maintain
  5. Automatic - Plugin handles everything
  6. GitHub-Style - Same syntax as GitHub markdown

Happy Diagramming! πŸ“Šβœ¨

Using jekyll-mermaid plugin for automatic diagram generation from native markdown.