Add support for Mermaid diagrams rendering in PDF output#3
Open
Tr8ch wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mermaid blocks now render as diagrams in the PDF instead of plain code.
The preprocessor catches
```mermaid ```fences before markdown runs and replaces each one with a base64 PNG<img>.Renderers, tried in this order:
mmdc(mermaid-cli) if it's on$PATH— works offline.mermaid.inkas the network fallback.If both fail, the fence is left as-is, so a missing
mmdcor no internet won't break the conversion. SetGHPDF_MERMAID_OFFLINE=1to skip the network step.I started with inline SVG. It looked clean for a 3-node flowchart and fell apart on anything real: Mermaid positions labels through HTML inside
<foreignObject>, and WeasyPrint doesn't run an HTML engine inside SVG. Node labels came out blank,erDiagramcolumns piled on top of each other, long edge labels instateDiagram-v2ran into their neighbours. Rasterizing in Chromium (whatmmdcandmermaid.inkdo internally) skips that whole problem. I'm using scale 3, which is enough for A4 without making the PDF huge.For offline use:
bash npm install -g @mermaid-js/mermaid-cli # or: brew install mermaid-cli