HeadlinesBriefing favicon HeadlinesBriefing.com

Adding Mermaid Diagrams to Jekyll Blogs

DEV Community •
×

Technical bloggers often need to create architecture diagrams, flowcharts, and sequence diagrams. Manually creating and attaching image files is tedious and hard to update. The article explains how to integrate Mermaid.js, a text-based diagram generator, into Jekyll static sites. This allows diagrams to be defined directly in Markdown code blocks and rendered automatically, streamlining the documentation workflow.

To set this up, you add a script to your Jekyll theme's `head.html` file. This script loads the Mermaid library from a CDN and includes JavaScript to convert Markdown code blocks with the `language-mermaid` class into renderable diagrams. The configuration sets `startOnLoad: false` to give developers control over when rendering happens, which is useful for dynamic content or single-page applications.

The guide provides syntax examples for various diagram types supported by Mermaid, including flowcharts, sequence diagrams, class diagrams, and Gantt charts. Using text-based definitions means diagrams can be version-controlled with Git and edited without opening separate graphics software. This approach is particularly valuable for software developers and engineers maintaining technical blogs or documentation sites.