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.…