Render Markdown to PDF from the command line — matching the exact look of the yzane "Markdown-PDF" VS Code extension. Same parser, same CSS, printed by your own Chrome. Plus Mermaid diagrams and embedded charts, so complete documents come out complete.
Works as a plain CLI and as a skill for AI coding agents — Claude Code, Cursor, Codex, and more (see SKILL.md).
🎯 Pixel-parity with the VS Code extension 📊 Mermaid + embedded SVG/PNG 🖨️ Prints via your installed Chrome
- ✨ What it does
- 📥 Install as a skill
- 🚀 Quick Start
- 📖 Usage
- 🎨 Project overrides
- 🔧 What it reproduces
⚠️ Limitations- 🧰 Prerequisites
- 🙌 Built by
- 📜 License
Most Markdown-to-PDF tools (pandoc, md-to-pdf) produce a different look — LaTeX styling or their own baked-in CSS. This one reproduces the yzane Markdown-PDF extension's pipeline end to end:
markdown-it (same options + plugins) → HTML with the extension's own CSS → printed by your Google Chrome via puppeteer-core, using the extension's default page options.
On top of that it:
- 📊 Renders Mermaid diagrams —
```mermaidfences become SVG (fail-soft: a broken diagram is left as source, not a failed document). - 🖼️ Embeds images and charts referenced by paths relative to the Markdown file, so SVG/PNG assets resolve and print.
- 📁 Batch-renders a single file, a list of files, or whole folders (optionally recursive).
- 📦 Downloads no browser — it drives the Chrome you already have.
Add it to your AI coding agent with the skills CLI:
npx skills add onsen-ai/markdown-pdf-skillOr install globally, for every project:
npx skills add onsen-ai/markdown-pdf-skill -gTarget a specific agent explicitly:
npx skills add onsen-ai/markdown-pdf-skill -a claude-code
npx skills add onsen-ai/markdown-pdf-skill -a cursorThe skill is copied into your agent's skills directory (e.g. ~/.claude/skills/), where it's discovered automatically — the agent reads SKILL.md and can render Markdown to PDF on request. See vercel-labs/skills for more install options.
The
skillsCLI needs Node 20.12+ or 22+. On Node 18 it fails withSyntaxError: ... does not provide an export named 'styleText'. Run the install under a newer Node (nvm use 20), or use the manual install below — the skill itself runs fine on Node 18+.
Clone straight into your agent's skills directory — works on any Node version:
# Claude Code
git clone https://github.com/onsen-ai/markdown-pdf-skill.git ~/.claude/skills/markdown-to-pdf
# Cursor
git clone https://github.com/onsen-ai/markdown-pdf-skill.git .cursor/skills/markdown-to-pdfMost agents discover skills automatically from their skills directory — no extra configuration needed.
Prefer to run it as a plain CLI instead? Skip this and see Quick Start.
# render one file -> report.pdf next to it
npx github:onsen-ai/markdown-pdf-skill report.md
# a whole folder, recursively, into one output dir
npx github:onsen-ai/markdown-pdf-skill ./docs --recursive --out ./pdfsnpx fetches the tool and its dependencies into its cache on first use and runs the md2pdf command — nothing is added to your project. All the options below work the same way. (You still need Node and Chrome — see Prerequisites.)
git clone https://github.com/onsen-ai/markdown-pdf-skill.git
cd markdown-pdf-skill
npm install # one-off
node scripts/md2pdf.mjs examples/sample.md # → examples/sample.pdfOpen examples/sample.pdf to see headings, tables, syntax highlighting, a task list, a Mermaid diagram, and an embedded chart — all in the extension's styling.
# single file -> RELEASES.pdf next to it
node scripts/md2pdf.mjs path/to/RELEASES.md
# every .md in a folder (PDFs written alongside each source)
node scripts/md2pdf.mjs "path/to/docs"
# recurse into subfolders, and collect all PDFs into one output dir
node scripts/md2pdf.mjs "path/to/docs" --recursive --out ~/Desktop/pdfs| Option | What it does |
|---|---|
--out <dir> |
Write PDFs to <dir> instead of next to each source. |
--recursive, -r |
Recurse into subfolders when a path is a directory. |
--css <file> |
Extra stylesheet applied last (overrides the standard look). Repeatable. |
--chrome <path> |
Chrome/Chromium/Edge executable (else auto-detected, then CHROME_PATH). |
--quiet |
Only print errors. |
The output filename is the source basename with a .pdf extension. Existing PDFs are overwritten.
The bundled styling (extension CSS + assets/styles/overrides.css) is the shared default. A project can layer its own tweaks with a small CSS file passed via --css — because it loads last, it wins the cascade, without touching the skill:
node scripts/md2pdf.mjs docs/ --css my-tweaks.css/* my-tweaks.css — e.g. let long paths in tables wrap instead of widening the column */
table code { font-size: 10px; white-space: normal; word-break: break-word; }The extension's defaults, all editable in scripts/md2pdf.mjs and assets/styles/:
- Parser:
markdown-itwithhtml: true,breaks: false,linkify: false, plusmarkdown-it-checkbox(task lists) andmarkdown-it-named-headers(heading anchors). Code highlighting viahighlight.js. - CSS: the extension's own
markdown.css,markdown-pdf.css, andtomorrow.css(default code theme), inlined at render time. Local tweaks live inoverrides.css, loaded last. - Page: A4 portrait; margins top 1.5cm, bottom/left/right 1cm;
printBackground: true. - Header: document title (filename) left, ISO date right, 9px.
- Footer:
pageNumber / totalPagescentred, 9px.
- Math (KaTeX / LaTeX) is not rendered by default. Add the
markdown-it-katexplugin plus KaTeX CSS to the script (same pattern as Mermaid) if you need it. - Remote images need network access at render time.
- Don't install inside a cloud-synced folder (OneDrive, Dropbox):
node_modulesis thousands of files and will trigger a sync storm. Keep it in a normal git repo and point it at your Markdown wherever it lives.
- Node.js ≥ 18
- Google Chrome (or Chromium/Edge). Auto-detected; on macOS it defaults to
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome.puppeteer-coredrives the existing browser, so nothing is downloaded.
Built by the team at Onsen — an AI-powered mental health companion for journaling, emotional wellbeing, and personal growth.
MIT — see LICENSE.
The bundled stylesheets in assets/styles/ (markdown.css, markdown-pdf.css, tomorrow.css) are from the yzane Markdown-PDF VS Code extension (MIT).