Menu

Rendering 25 Mermaid diagrams into a print PDF (and what broke)
📰

Rendering 25 Mermaid diagrams into a print PDF (and what broke)

DEV Community: go·Sazardev·13 days ago
#U3of4Ur2
#devtogo#devto#dev#mermaid#diagrams
Long article (829 words) — no AI summary yet.
Reading 0:00
15s threshold

I maintain a free book, Networking with Go, Made Easy , that ships as a web reader, a PDF and an EPUB from the same Markdown sources. The web reader renders Mermaid diagrams in the browser. The PDF did not: it printed 25 blocks of flowchart TB and sequenceDiagram as literal source code.

This is the story of the build step that fixed it, including the parts that were not obvious.

Three constraints, one conclusion

The PDF is produced by go-pretty-pdf , which composes the MDX into HTML and prints it with headless Chrome. Three details of that pipeline ruled out the obvious fixes:

It has no Mermaid support. A ` mermaid fence becomes an ordinary code block.

It blocks subresources by default. Network and file:// fetches are blocked, so an <img src="diagram.svg"> inside the composed page never loads.

It prints immediately after the load event.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.