agentleFS
darblinkodarblinko/claude-skills/skills/markdown-to-pdf/SKILL.md

markdown-to-pdf

Skill0 starsChanged 16 days agoApache-2.0View on GitHub

Use when asked to turn a Markdown file into a PDF, export a .md report for printing or sharing, or produce a printable deliverable from Markdown, especially documents containing mermaid diagrams, wide tables, or that need page numbers and a running header.

12 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use the path where the skill is installed if it is not under ~/.claude/skills.

    line 30
  2. Distinctive:

    Check: no diagram clipped at a page edge, no table or code block running off the right margin, no page of pure whitespace (a blank page …

    line 66

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Markdown to PDF

Overview

Renders a Markdown file to a print-quality PDF via headless Chromium. Mermaid diagrams come out as vector SVG, tables repeat their header row across page breaks, and every page gets a running header and Page N of M footer.

Oversized diagrams are the hard part, and the script handles them: a diagram taller than the page is sliced across consecutive pages, and one far wider than the page is wrapped into stacked left-to-right bands. Both keep labels readable instead of shrinking the figure into an unreadable sliver.

Rendering is local. The page runs under a Content Security Policy that lets only the renderer's own scripts run and blocks every external fetch, and the browser aborts any request that gets past it. Scripts, event handlers and remote resources in raw HTML are blocked and listed on stderr.

Usage

node ~/.claude/skills/markdown-to-pdf/md2pdf.js <input.md> [output.pdf] [options]

Use the path where the skill is installed if it is not under ~/.claude/skills.

Output defaults to the input path with .pdf substituted. Options:

OptionEffect
--note "TEXT"Right-hand running-header text (e.g. a status or confidentiality caveat)
--format Letter|A4Paper size (default Letter)
--landscapeLandscape orientation

The document title (browser tab, PDF metadata, left-hand running header) comes from the first # heading, falling back to the filename.

Mermaid diagrams are fenced code blocks with the info string mermaid, with backticks or tildes. Markdown images with a local path are read relative to the Markdown file and embedded. A missing local image, or an image with an http or https URL, stops the render with an error: download remote images first.

The script prints a line per oversized diagram saying how it was handled, and a blocked line per script or resource the page was not allowed to run or load. Relay anything still flagged as too small, and any blocked line, to the user.

First run installs markdown-it, mermaid, and playwright-core into the skill directory automatically. Chromium is found in this order: CHROME_PATH, the build pinned by playwright-core at Playwright's install path, the newest build in the Playwright cache, then system Chrome/Chromium.

After rendering, always verify

The command exits non-zero if a diagram fails, but it cannot see layout problems. Render pages to images and look at them:

pdftoppm -png -r 75 out.pdf /tmp/preview/p    # then Read the PNGs

Check: no diagram clipped at a page edge, no table or code block running off the right margin, no page of pure whitespace (a blank page means content was clipped, not merely pushed). Report the page count to the user.

Design notes (why it is built this way)

Each of these fixes a bug that is invisible until you look at rendered pages:

  • Chrome clips; it does not slice or scroll. Anything overflowing the print margin box is silently cut: an SVG taller than the page loses its lower half, a long code line loses its right end. Hence white-space: pre-wrap on pre, and the diagram slicing/banding rather than plain scaling.
  • Page margins are 6 mm; <main> is padded 10 mm. Body text keeps a readable measure while .mermaid-slot uses negative margins to reach nearly the full sheet. A diagram cannot be given more room by breaking out past the margins, because that region is clipped, so the margins themselves have to be narrow.
  • Mermaid's inline width/max-width are stripped after render. Mermaid writes them on the <svg>, where they outrank the stylesheet and let wide flowcharts run off the page. The script removes them and scales via the viewBox.
  • The viewport is set to the printed diagram width so mermaid measures label wrapping at the width the diagram will occupy in print.
  • Slices and bands overlap (36 px / 110 px) so a node cut by a seam reappears whole on the adjacent slice.
  • thead { display: table-header-group } repeats table headers on continuation pages; tr { break-inside: avoid } stops rows splitting mid-cell.

Common problems

SymptomCause / fix
Diagram cut off at a page edgeInline SVG sizing survived, or margins were widened. See design notes.
Blank page containing only a faint boxA diagram overflowed and was clipped; the slicing threshold did not trigger.
Diagram still flagged too smallDense and neither tall nor wide enough to band. It is vector, so it zooms; for print, try --landscape or ask whether the diagram can be split at the source.
Large blank gap before a diagramA diagram that will not fit is pushed whole to the next page. Expected.
Source file changed mid-buildstat the .md against the .pdf afterwards; rerun if it moved.

Styling

report.css holds the print stylesheet: serif body, sans headings and tables, navy accent, banded rows, callout styling for blockquotes. Edit it to restyle; it applies to every document rendered by this skill.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.