markdown_to_pdf
Convert Markdown files to styled PDFs with selectable rendering engines and color themes, preserving math, tables, code blocks, and clickable links for printing or on-screen reading.
Instructions
Convert a Markdown file (.md) to a styled PDF.
Uses markdown-it-py for parsing. Supports two rendering backends:
- engine="chromium" (default): Uses Playwright/Chromium for PDF output.
Full MathJax SVG support — recommended for math-heavy documents.
- engine="weasyprint": Lightweight, good for simple documents without math.
Supports Chinese fonts, tables, code blocks, blockquotes, and page numbers.
Three color themes are available: white for printing, warm sepia for
low-glare reading, and a dark theme inspired by One Dark Pro Night Flat.
Preserves clickable web and local file links, including file:// URLs and
relative paths into other repositories, resolved from the source directory.
Call inspect_pdf_links first. Existing unambiguous derived PDFs replace
local Markdown/HTML targets; absent PDFs leave the source link unchanged.
Multiple PDF candidates require pdf_targets; other file formats stay intact.
Args:
file_path: Absolute path to the .md file.
output_path: Absolute path for the output .pdf file.
If empty, the PDF is saved next to the source with the
same stem (e.g. /tmp/report.md → /tmp/report.pdf).
engine: Rendering backend — "chromium" (default) or "weasyprint".
theme: Color theme — "print" (white, default), "sepia" (warm),
or "one-dark-pro" (One Dark Pro Night Flat-inspired).
pdf_targets: Reviewed source-to-PDF paths, or null values to keep sources.
Relative paths resolve from the source directory.
pdf_destinations: Original hrefs mapped to fragments from resolve_pdf_destination.
link_policy: "prefer-pdf" selects existing PDFs; "preserve" keeps sources.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| theme | No | ||
| engine | No | chromium | |
| file_path | Yes | ||
| link_policy | No | prefer-pdf | |
| output_path | No | ||
| pdf_targets | No | ||
| pdf_destinations | No |