No release in over 3 years
Jekyll plugin that converts mermaid diagram code blocks to SVG files at build time using the mmdc CLI. Eliminates the need for client-side mermaid.js (~2MB) by generating static SVG files with intelligent caching.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.3
~> 3.13
~> 1.81
~> 0.22

Runtime

>= 4.0, < 5.0
 Project Readme

Jekyll Mermaid Prebuild

Gem Version code coverage

Pre-render Mermaid diagrams to SVG at Jekyll build time, eliminating the need for client-side JavaScript.

Why?

The mermaid.js library is ~2MB minified. This plugin renders your diagrams to static SVG files during the Jekyll build, so your visitors don't need to download and execute any JavaScript.

Features

  • Converts mermaid code blocks to SVG files at build time
  • Supports both backtick (```) and tilde (~~~) fenced code blocks
  • Intelligent caching - only regenerates changed diagrams
  • Clickable diagrams - link to full-size SVG for complex diagrams
  • Configurable output directory

Requirements

Installing mermaid-cli

npm install -g @mermaid-js/mermaid-cli

Puppeteer Dependencies (Linux/WSL)

The mermaid CLI uses Puppeteer (headless Chrome). On Debian/Ubuntu/WSL, install the required libraries:

sudo apt-get update
sudo apt-get install -y libgbm1 libasound2 libatk1.0-0 \
  libatk-bridge2.0-0 libcups2 libdrm2 libxcomposite1 \
  libxdamage1 libxfixes3 libxrandr2 libxkbcommon0 \
  libpango-1.0-0 libcairo2 libnss3 libnspr4

Installation

Add to your Gemfile:

group :jekyll_plugins do
  gem "jekyll-mermaid-prebuild"
end

Run:

bundle install

Usage

Write mermaid diagrams in your markdown using fenced code blocks:

```mermaid
flowchart LR
  A[Start] --> B{Decision}
  B -->|Yes| C[OK]
  B -->|No| D[Cancel]
```

The plugin will automatically convert these to SVG files at build time.

Output

The mermaid code block is replaced with:

<figure class="mermaid-diagram">
  <a href="/assets/svg/abc12345.svg">
    <img src="/assets/svg/abc12345.svg" alt="Mermaid Diagram">
  </a>
</figure>

The image is wrapped in a link to itself, allowing users to click for a full-size view of complex diagrams.

Configuration

Add to your _config.yml:

mermaid_prebuild:
  enabled: true          # default: true
  output_dir: assets/svg # default: assets/svg

Options

Option Default Description
enabled true Enable/disable the plugin
output_dir assets/svg Directory for generated SVG files

Caching

Generated SVGs are cached in .jekyll-cache/jekyll-mermaid-prebuild/. The cache key is based on the diagram content, so:

  • Unchanged diagrams are served from cache (fast rebuilds)
  • Modified diagrams are automatically regenerated
  • Different diagrams with different content get different cache keys

To clear the cache:

rm -rf .jekyll-cache/jekyll-mermaid-prebuild/

Troubleshooting

"mmdc not found"

Install the mermaid CLI:

npm install -g @mermaid-js/mermaid-cli

Verify installation:

mmdc --version

"Puppeteer cannot launch headless Chrome"

Install the required system libraries (see Puppeteer Dependencies above).

Diagrams not converting

  1. Check build output for MermaidPrebuild: messages
  2. Verify mmdc works: mmdc -i test.mmd -o test.svg
  3. Clear cache: rm -rf .jekyll-cache/jekyll-mermaid-prebuild/

Development

Setup

git clone https://github.com/Texarkanine/jekyll-mermaid-prebuild.git
cd jekyll-mermaid-prebuild
bundle install

Testing

bundle exec rspec

Code Quality

bundle exec rubocop

Contributing

See CONTRIBUTING.md for development guidelines.