Architecture
md2pdf converts Markdown to PDF through a four-stage pipeline.
Pipeline overview
- Parse — goldmark converts Markdown to HTML with GFM extensions (tables, fenced code blocks, strikethrough). Mermaid code blocks are extracted and replaced with placeholders.
- Render diagrams — each Mermaid block is rendered to SVG via the
mmdcCLI. - Build HTML — a self-contained HTML file is assembled with GitHub-flavored CSS,
@font-facedeclarations for Noto Sans CJK JP, and the rendered SVGs injected inline. - Print PDF — a headless Chromium browser (via Playwright) loads the HTML and prints it to PDF.
Source layout
internal/converter/
converter.go # Orchestrates the pipeline, manages temp directory
parser.go # Stage 1 — goldmark parsing
mermaid.go # Stage 2 — mmdc SVG rendering
html.go # Stage 3 — HTML assembly
pdf.go # Stage 4 — Chromium PDF printing
cmd/md2pdf/
main.go # CLI entry point
flags.go # Argument parsing, auto-detection
External dependencies
| Dependency | Purpose |
|---|---|
| goldmark | Markdown to HTML (Go library) |
| mmdc | Mermaid diagram rendering |
| Playwright + Chromium | HTML to PDF |
| Noto Sans CJK JP | Japanese font support |
Last updated: 2026-04-15