generated from srid/ema-template
-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Description
Problem
Currently, Mermaid diagrams require client-side JavaScript loaded from a CDN (cdn.jsdelivr.net/npm/mermaid). This means generated sites cannot render diagrams when viewed offline.
Mermaid is opt-in via <snippet var="js.mermaid" /> in page.headHtml, configured in index.yaml.
Proposed Solution
Render mermaid code blocks to inline SVG at build time, eliminating the CDN dependency entirely. This is the approach sukr.io uses.
Implementation
- Add
@mermaid-js/mermaid-cli(mmdc) as a build dependency (via Nix) - Create a new Pandoc block renderer (
Emanote/Pandoc/Renderer/Mermaid.hs) that interceptsCodeBlocknodes with themermaidclass - Run
mmdcto render the mermaid definition to SVG - Replace the code block with an inline
RawBlock "html" svgContent - Graceful fallback: if rendering fails, preserve the original code block with an error comment
Benefits
- Generated site works fully offline
- No client-side JavaScript needed for diagrams
- Faster page loads (no JS parsing/rendering delay)
- Diagrams are part of the HTML — visible to search engines and screen readers
Tradeoffs
- Adds
mmdcas a build-time dependency - Some complex diagram types may render differently than the JS version
- Build time increases slightly
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels