Diagram Rendering (Client-Side)

Starting from version 0.66.0, MarkCharm supports native mermaid blocks. The compiler dynamically detects the presence of the diagram without breaking structural AST parsing, surgically injecting the asynchronous JavaScript module from the Mermaid.js library into the final document.

Basic Flowchart (Graph TD)

graph TD
    A[Hard work] -->|Yields| B(Success)
    B --> C{More work?}
    C -- Yes --> A
    C -- No --> D[Retire]

Gantt Chart

gantt
    title Siren Project Development Schedule
    dateFormat  YYYY-MM-DD
    section Research
    Feasibility Study               :a1, 2026-08-22, 1d
    section Implementation
    Structural Parsing (Phase 3)    :a2, after a1, 1d
    JS Injection Router (HTML Phase):a3, after a1, 1d
    section Testing
    Test Suite & Regression         :a4, after a3, 1d

Class Diagram (UML)

classDiagram
    Animal <|-- Duck
    Animal <|-- Fish
    Animal <|-- Zebra
    Animal : +int age
    Animal : +String gender
    Animal: +isMammal()
    Animal: +mate()
    class Duck{
        +String beakColor
        +swim()
        +quack()
    }
    class Fish{
        -int sizeInFeet
        -canEat()
    }
    class Zebra{
        +bool is_wild
        +run()
    }

Sequence Diagram

sequenceDiagram
    participant AST as AST Analyzer
    participant HTML as HTML Renderer
    participant CDN as jsDelivr (CDN)
    
    AST->>AST: Detects ```mermaid block
    AST->>HTML: Flags self.used_mermaid = True
    HTML->>CDN: Requests mermaid.esm.min.mjs (Async)
    CDN-->>HTML: Delivers JS Module
    HTML->>HTML: Injects <script type="module">
    HTML-->>AST: Returns clean HTML with embedded CSS

Width Control and Automatic Numbering (Wrapper)

When you enclose a raw Mermaid diagram inside a structural diagram block, you gain control over numbering, captions, and onscreen image sizing! See the difference using width="50%":

Diagram 1. Sequence Diagram (Compact)
sequenceDiagram
    participant AST as AST Analyzer
    participant HTML as HTML Renderer
    
    AST->>HTML: Renders AST
    HTML->>HTML: Adjusts width to 50%

Source: Prepared by the author

As shown in “Sequence Diagram (Compact)”, the image was scaled down and centered, and now includes a caption and numbering!

Static Rendering (Embedded SVG)

By default, MarkCharm uses the CDN (Client-Side) strategy, which injects Mermaid JavaScript and delegates rendering to the reader's browser. This keeps the HTML file tiny.

However, if you need to generate a 100% self-contained document (without internet or JavaScript dependency) — such as for direct PDF conversion or strict offline reading — you can force graph compilation to an embedded static SVG image using the render="kroki" attribute (static cloud) or render="cli" (local processing via mmdc).

MOCKED MERMAID SVG

This pie chart above depends on no browser script; it was transformed into a pure <svg> tag during the compilation phase!

Below are static (embedded) versions of the same diagrams presented in the first section. Note that they use the exact same syntax, simply adding {render="kroki"}.

Basic Flowchart (Static)

graph TD;
    A[Mermaid.js] -->|Converts to| B(SVG);
    B --> C{Embedded in HTML};
    C -- Yes --> A
    C -- No --> D[Retire]

Gantt Chart (Static)

MOCKED MERMAID SVG