Mermaid Diagram Compatibility Guidelines
When creating or updating Mermaid diagrams for the documentation site, keep in mind the following compatibility guidelines to ensure they render correctly.
Common Issues
The MkDocs Material integration with Mermaid (version 11.6.0) may have different syntax requirements than the latest version of Mermaid. Here are the most common issues:
- HTML in Nodes: HTML tags inside nodes may not render correctly:
# DON'T DO THIS ❌
flowchart TD
A["<a href='link.md'>Link Text</a>"]
- Complex Syntax: Some newer Mermaid features may not be supported:
# MAY NOT WORK ⚠️
timeline
title Timeline of Events
section 2023
Launch: Project initiated
Alpha: First alpha release
- Special Characters: Some special characters might cause rendering issues:
# BE CAREFUL WITH ⚠️ flowchart TD A["Node with & < > characters"]
Best Practices
Follow these best practices for creating compatible Mermaid diagrams:
- Keep It Simple: Use basic flowchart syntax whenever possible:
# DO THIS ✅
flowchart TD
A[Start] --> B{Decision}
B -->|Yes| C[Process]
B -->|No| D[End]
- Use Comments for Links: Instead of HTML links, use comments and provide links below:
# DO THIS ✅
flowchart TD
A[Start] --> B[See documentation]
See detailed documentation here
-
Test Locally: Always preview your diagrams locally before pushing changes.
-
Use the Live Editor: Check your diagrams in the Mermaid Live Editor and specify version 11.6.0 for compatibility testing.
Fixing Common Errors
If you encounter errors:
-
Syntax Error in Text: This usually means there's an unescaped character or unsupported syntax:
-
Check for special characters
- Simplify your diagram
-
Make sure your diagram type is supported
-
Rendering Issues: If the diagram parses but looks wrong:
-
Check for proper node connections
- Make sure your subgraphs are properly defined
-
Reduce complexity of the diagram
-
Missing Elements: If some elements don't appear:
- Check for unsupported features
- Make sure you're not using newer syntax features
Example of Fixing a Diagram
Original (Problematic):
flowchart TD
A["<a href='docs.md'>Documentation</a>"] --> B["Process with & special chars"]
click C "https://example.com"
C --> D
Fixed Version:
flowchart TD
A["Documentation"] --> B["Process with special chars"]
C[External resource] --> D
See Documentation for more details. External resource provides additional context.
By following these guidelines, you'll ensure that your Mermaid diagrams render consistently in the documentation site.