Render Mermaid diagrams¶
In this tutorial, we will add a Mermaid diagram to Markdown and produce a PDF that contains the rendered diagram.
By the end, you will have a PDF with a rendered flowchart and you will see how Mermaid errors are reported.
Create the document¶
Create diagram.md:
Convert it¶
Run:
From the repository, use cargo run -- diagram.md instead.
You should see:
Open diagram.pdf. The diagram should appear where the fenced Mermaid block was in the Markdown file.
Most diagrams render with the default timeout. Increase the budget only when a large diagram or slow network needs more time:
Notice the failure behavior¶
Now change this line:
B --> C[Print PDF]
to this incomplete line:
B -->
Then run the command again.
You should see an error that starts with:
The command fails before reporting success.
Recap¶
You added a Mermaid fenced block, rendered it into a PDF, and saw how md-to-pdf reports Mermaid failures before writing a successful result.
Next steps¶
- Use Use Mermaid offline for reproducible builds.
- Diagnose failures with Debug rendering.
- Check Error messages when a diagram fails.