Skip to content

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:

# Release Flow

```mermaid
graph TD
  A[Write Markdown] --> B[Render Mermaid]
  B --> C[Print PDF]
```

Convert it

Run:

md-to-pdf diagram.md

From the repository, use cargo run -- diagram.md instead.

You should see:

Wrote diagram.pdf

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:

md-to-pdf diagram.md --virtual-time-budget 15000

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:

Error: Mermaid render failed:

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