Mermaid Diagram Configuration Guide
This comprehensive guide covers setup, implementation, and troubleshooting of Mermaid diagrams in Jekyll sites. Mermaid allows you to create diagrams and visualizations using simple text syntax.
Table of Contents
- Overview
- Installation & Setup
- Configuration
- Usage Examples
- Troubleshooting
- Performance Optimization
- References & Credits
Overview
Mermaid is a JavaScript-based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically. It supports:
- Flowcharts
- Sequence diagrams
- Class diagrams
- State diagrams
- Entity relationship diagrams
- User journey diagrams
- Gantt charts
- Pie charts
- Git graphs
- And more…
Why This Implementation?
Our Jekyll site uses a hybrid approach combining:
- jekyll-mermaid plugin for build-time processing
- Runtime JavaScript conversion for fenced code blocks
- CDN delivery for performance and reliability
This ensures compatibility across different content authoring methods while maintaining optimal performance.
Installation & Setup
1. Gemfile Configuration
Add the jekyll-mermaid plugin to your Gemfile:
2. Jekyll Configuration
Configure Mermaid in your _config.yml:
3. Layout Integration
Add Mermaid support to your layouts. For universal support, add to _layouts/default.html:
4. Install Dependencies
Configuration
Basic Configuration Options
In _config.yml, you can customize Mermaid settings:
Advanced Layout-Specific Configuration
For specialized layouts (e.g., presentation slides), you can create custom configurations:
Usage Examples
Method 1: Fenced Code Blocks (Recommended)
This is the preferred method as it’s compatible with most Markdown processors and avoids build-time HTML wrapping issues:
Method 2: Jekyll Liquid Tags
Note: This method can cause issues with <p> tag wrapping. Use fenced code blocks when possible.
Example Diagram Types
Flowchart
Sequence Diagram
Class Diagram
Troubleshooting
Common Issues and Solutions
1. Diagrams Render as Code Blocks
Symptoms: Mermaid syntax appears as plain text in <pre><code> blocks instead of rendered diagrams.
Causes:
- Missing JavaScript initialization
- Script loading after content render
- Incorrect layout configuration
Solutions:
2. “Syntax Error” Messages in Diagrams
Symptoms: Diagram container shows “Syntax error in graph” or similar error text.
Causes:
- HTML entities in diagram text (e.g.,
>instead of>) - Jekyll Liquid processing interference
- Invalid Mermaid syntax
Solutions:
- Use fenced code blocks instead of Liquid tags
- Verify diagram syntax at Mermaid Live Editor
- Check for HTML entity encoding in source
3. Mixed Content Warnings
Symptoms: Browser console shows mixed content warnings when loading Mermaid from CDN on HTTPS sites.
Solutions:
4. Script Loading Race Conditions
Symptoms: Intermittent rendering failures, especially on slower connections.
Solutions:
Debugging Tools
Browser Console Debugging
E2E Testing Validation
Use Playwright tests to ensure reliable rendering:
Performance Optimization
CDN Configuration
Use a reliable CDN with proper versioning:
Lazy Loading
For pages with many diagrams, consider lazy loading:
Bundle Size Optimization
Consider self-hosting for production:
References & Credits
Internal Documentation
- Mermaid Quick Start: Quick Setup Guide - Rapid setup and basic usage patterns for immediate productivity
- Mermaid Diagrams Sample: Mermaid Diagrams Showcase - Live examples of all supported diagram types
- Mermaid Examples: Comprehensive Mermaid Examples - Extended collection of real-world diagram patterns and use cases
- Quick Start Guide: Getting Started - Rapid setup guide for the complete development environment
- Testing Documentation: See our comprehensive E2E testing setup for Mermaid diagram validation
Official Documentation
- Mermaid Official Documentation: https://mermaid.js.org/
- Mermaid GitHub Repository: https://github.com/mermaid-js/mermaid
- Mermaid Live Editor: https://mermaid.live/
Jekyll Integration
- jekyll-mermaid Plugin: https://github.com/jasonbellamy/jekyll-mermaid
- Jekyll Official Plugins: https://jekyllrb.com/docs/plugins/
CDN Providers
- jsDelivr: https://www.jsdelivr.com/
- unpkg: https://unpkg.com/
- cdnjs: https://cdnjs.com/
Testing & Validation
- Playwright Testing: https://playwright.dev/
- Accessibility Testing: https://github.com/dequelabs/axe-core
- Internal E2E Tests: Our custom Mermaid testing suite validates diagram rendering across all supported browsers
Community Resources
- Mermaid Syntax Guide: https://mermaid.js.org/syntax/flowchart.html
- Jekyll Community: https://talk.jekyllrb.com/
MIJUG .NET Workspace Integration
- Performance Optimization: This implementation follows our workspace’s performance targets (< 12s builds, < 90s test suite)
- Accessibility Standards: WCAG 2.1 AA compliance enforced via automated testing
- Multi-Browser Support: Validated across Chromium, Firefox, and WebKit using our specialized test runner
-
Conditional Loading: Optimized script loading only when
use_mermaid: trueis set in page front matter - Development Workflow: Integrated with FrontMatter CMS and Jekyll drafts workflow for streamlined content creation
Contributing
This implementation was developed for the MIJUG .NET workspace and incorporates best practices from:
- Mermaid.js community for syntax and rendering guidance
- Jekyll community for plugin integration patterns
- Playwright team for E2E testing methodologies
- jsDelivr team for CDN reliability recommendations
Version History
- v1.0 (2025-08-08): Initial implementation with hybrid approach
- v1.1 (2025-08-08): Added runtime fenced code block conversion
- v1.2 (2025-08-08): Enhanced error handling and debugging tools
License Acknowledgments
- Mermaid.js: MIT License - Copyright (c) 2014 - 2024 Knut Sveidqvist
- jekyll-mermaid: MIT License - Copyright (c) 2015 Jason Bellamy
- Jekyll: MIT License - Copyright (c) 2008-2015 Tom Preston-Werner
For the most current information, always refer to the official documentation links provided above.
My Info Just Under Glass