Hugo Story Theme
Archives Slides Talks

Render Mermaid Diagrams with Story

Published Aug 19, 2018 by Lionel VICTOR in Demo at https://story-customized.tchinchow.net/mermaid/

A Work In Progress…

This page is a first attempt at integrating mermaid-js diagrams.

It is a Work in Progress. Here follows a non exhaustive list of things to improve or fix:

  • Integration with “feature-figcaption” may need reviewing

However, some features are already working:

  • “feature-fignum” does increment the figures’ caption number,
  • “feature-figcaption-hidden” sort of work but requires further testing, and
  • most important diagrams are showing properly (even though styling needs to be worked on)
  • diagrams are not properly aligned / centered
  • git diagrams are looking better (font size was adjusted in mermaid’s global configuration)
  • feature’s blog article now stands out with its own picture+thumbnail. It also contains code samples for most important diagrams.

The guided Tour

Please join me as I walk you through the classical mermaid scripts:

  • SequenceDiagram (read documentation):

    {{< mermaid "some caption" >}}
    sequenceDiagram
        participant Alice
        participant Bob
        Alice->>John: Hello John, how are you?
        loop Healthcheck
            John->John: Fight against hypochondria
        end
        Note right of John: Rational thoughts <br/>prevail...
        John-->Alice: Great!
        John->Bob: How about you?
        Bob-->John: Jolly good!
    {{< /mermaid >}}
    
    sequenceDiagram participant Alice participant Bob Alice->>John: Hello John, how are you? loop Healthcheck John->John: Fight against hypochondria end Note right of John: Rational thoughts
    prevail... John-->Alice: Great! John->Bob: How about you? Bob-->John: Jolly good!
    some caption

    Note:
    Please notice how the caption that was provided as a parameter of the Hugo shortcode appears when you hover you mouse over the diagram.

  • Flowcharts (read documentation):

    {{< mermaid >}}
    graph LR;
        A[Hard edge] -->|Link text| B(Round edge)
        B --> C{Decision}
        C -->|One| D[Result one]
        C -->|Two| E[Result two]
    {{< /mermaid >}}
    
    graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two]
  • GANTT diagram (read documentation):

    {{< mermaid >}}
    gantt
        dateFormat  YYYY-MM-DD
        title Adding GANTT diagram functionality to Story
        section A section
        Completed task            :done,    des1, 2014-01-06,2014-01-08
        Active task               :active,  des2, 2014-01-09, 3d
        Future task               :         des3, after des2, 5d
        Future task2              :         des4, after des3, 5d
        section Critical tasks
        Completed task in the critical line :crit, done, 2014-01-06,24h
        Implement parser and jison          :crit, done, after des1, 2d
        Create tests for parser             :crit, active, 3d
        Future task in critical line        :crit, 5d
        Create tests for renderer           :2d
        Add to mermaid                      :1d
    {{< /mermaid >}}
    
    gantt dateFormat YYYY-MM-DD title Adding GANTT diagram functionality to Story section A section Completed task :done, des1, 2014-01-06,2014-01-08 Active task :active, des2, 2014-01-09, 3d Future task : des3, after des2, 5d Future task2 : des4, after des3, 5d section Critical tasks Completed task in the critical line :crit, done, 2014-01-06,24h Implement parser and jison :crit, done, after des1, 2d Create tests for parser :crit, active, 3d Future task in critical line :crit, 5d Create tests for renderer :2d Add to mermaid :1d
  • Class diagram (read documentation):

    {{< mermaid >}}
    %%{
      init: {
        "theme": "base",
        "themeVariables": {
          "lineColor": "#ff0000"
        }
      }
    }%%
    classDiagram
        Class01 <|-- AveryLongClass : Cool
        Class03 *-- Class04
        Class05 o-- Class06
        Class07 .. Class08
        Class09 --> C2 : Where am i?
        Class09 --* C3
        Class09 --|> Class07
        Class07 : equals()
        Class07 : Object[] elementData
        Class01 : size()
        Class01 : int chimp
        Class01 : int gorilla
        Class08 <--> C2: Cool label
    {{< /mermaid >}}
    
    %%{ init: { "theme": "base", "themeVariables": { "lineColor": "#ff0000" } } }%% classDiagram Class01 <|-- AveryLongClass : Cool Class03 *-- Class04 Class05 o-- Class06 Class07 .. Class08 Class09 --> C2 : Where am i? Class09 --* C3 Class09 --|> Class07 Class07 : equals() Class07 : Object[] elementData Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label
  • Git graph (experimental):

    {{< mermaid >}}
    gitGraph:
    options
    {
        "nodeSpacing": 64,
        "nodeRadius": 8
    }
    end
        commit
        branch newbranch
        checkout newbranch
        commit
        commit
        checkout master
        commit
        commit
        merge newbranch
    {{< /mermaid >}}
    
    gitGraph: options { "nodeSpacing": 64, "nodeRadius": 6 } end commit branch newbranch checkout newbranch commit commit checkout master commit commit merge newbranch

Read next: Maps with Leaflet.js.

Lionel

Lionel VICTOR is an applied cryptography engineer and an enthusiastic Story user. He started augmenting the original Hugo’s Story theme with his own derivative called “Story-Customized”.

Find out more about Lionel on LinkedIn.

Story logo

© 2025 Baron Schwartz / Lionel VICTOR