agentleFS
eins78eins78/agent-skills/skills/pandoc/SKILL.md

pandoc

Skill2 starsChanged 14 days agoMITView on GitHub

Use when converting documents between formats — HTML, Markdown, DOCX, PDF, LaTeX, EPUB, reStructuredText, Org, JIRA, CSV, Jupyter notebooks, slides, and 60+ others. Triggers: convert file, export to PDF, make a PDF, print to PDF, printable PDF, A4 print, fold-to-A5 booklet, turn this into markdown, HTML to markdown, DOCX to markdown, markdown to DOCX, generate slides, create EPUB, format conversion, pandoc, document conversion. Always prefer pandoc over ad-hoc conversion scripts.

5 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

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    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:

    Always use -s for HTML files, LaTeX documents, and slide decks.

    line 215

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Pandoc

Universal document converter. Reader → AST → Writer pipeline with 60+ input and 80+ output formats. Prefer pandoc over writing custom conversion scripts — one command replaces most python-docx, beautifulsoup4, or markdown library usage.

Quick Reference

FlagPurpose
-f FORMATInput format (auto-detected from file extension)
-t FORMATOutput format (auto-detected from extension)
-o FILEOutput file (stdout if omitted)
-sStandalone — complete document with header/footer
--wrap=noneDon't rewrap lines (preserve original line breaks)
--extract-media=DIRExtract images from DOCX/EPUB/ODT
--tocGenerate table of contents
--number-sectionsNumber section headings
--pdf-engine=ENGINEPDF backend (default: pdflatex)
--reference-doc=FILEStyle template for DOCX/ODT/PPTX output
--template=FILECustom output template
--embed-resourcesEmbed images/CSS inline (HTML)
-V KEY=VALUESet template variable
-L SCRIPTApply Lua filter
--shift-heading-level-by=NAdjust heading levels
--columns=NLine wrap width (default 72)

Common Recipes

HTML → Markdown

pandoc -f html -t gfm -o output.md input.html
pandoc -f html -t gfm --wrap=none https://example.com/page  # from URL

Markdown → HTML

pandoc -s -o output.html input.md                    # standalone page
pandoc -s --toc --css=style.css -o output.html input.md  # with TOC + CSS
pandoc -t html input.md                              # fragment only (no <head>)

DOCX → Markdown

pandoc --extract-media=media/ --wrap=none -o output.md input.docx

Markdown → DOCX

pandoc -o output.docx input.md
pandoc --reference-doc=template.docx -o output.docx input.md  # styled

Markdown → PDF

Requires a LaTeX engine (or alternative). See ${CLAUDE_SKILL_DIR}/references/pandoc-install.md for setup.

pandoc -o output.pdf input.md                           # default (pdflatex)
pandoc --pdf-engine=xelatex -o output.pdf input.md      # Unicode/custom fonts
pandoc --pdf-engine=typst -o output.pdf input.md        # lightweight, no LaTeX
pandoc --pdf-engine=weasyprint -t html -o output.pdf input.md  # via HTML/CSS

Compact A4 print PDF (Marked-style, with Japanese + emoji)

For printable docs that match the look of Marked 2's GitHub/Swiss styles — 9pt body, bold heading hierarchy, tight A4 margins, full Unicode + emoji support via Apple system font fallback. Uses pandoc → HTML → headless Chrome; no LaTeX needed.

"${CLAUDE_SKILL_DIR}/scripts/md2pdf-print.sh" input.md output.pdf

The wrapper:

  1. Pipes markdown through pandoc with --embed-resources and the bundled themes/marked-print.css.
  2. Renders with chrome --headless=new --print-to-pdf.

Why not pandoc's own PDF engines? xelatex/typst/weasyprint all need extra fonts to render Japanese + emoji together. Headless Chrome already has Apple's full font stack and emoji color font available, so glyph fallback "just works" for any script.

Why not Marked 2's own PDF export? On macOS 26.3.1, Marked's "Export PDF" clips ~5–10pt off the left edge of every page in all styles. This pipeline bypasses the underlying Quartz PDFContext bug entirely.

Trade-off: output PDFs are ~4× larger than LaTeX output because Chrome embeds font subsets. Acceptable for one-shot print; not ideal for distribution-sized PDFs. Page count and density match Marked 2 closely, so it works well for booklet folding (e.g., A4 fold-to-A5).

Long lines in fenced code blocks wrap at the page edge (CSS sets white-space: pre-wrap; overflow-wrap: anywhere) so they don't get silently clipped. If you'd rather keep lines unbroken, break them in the source.

Pandoc has no Chrome --pdf-engine (as of 3.9). Even if one ships later, this wrapper still gives explicit control over headless flags and the print stylesheet, which is the reason to keep it.

Jupyter Notebook ↔ Markdown

pandoc -o output.md notebook.ipynb                    # notebook → markdown
pandoc -o output.ipynb input.md                       # markdown → notebook

Markdown → Slides

pandoc -t revealjs -s -o slides.html input.md         # reveal.js
pandoc -o slides.pptx input.md                        # PowerPoint
pandoc -t beamer -o slides.pdf input.md               # LaTeX Beamer

EPUB

pandoc -o book.epub chapter1.md chapter2.md metadata.yaml

Markdown → Kindle EPUB

For markdown destined for an e-reader — reflowable text, adjustable font size, and a working table of contents. Produce EPUB, not PDF: a PDF page is a fixed canvas and only zooms/pans on a 6" screen, while Send-to-Kindle converts EPUB into the device's own reflowable format on delivery.

"${CLAUDE_SKILL_DIR}/scripts/md2kindle-epub.sh" -o out.epub input.md
"${CLAUDE_SKILL_DIR}/scripts/md2kindle-epub.sh" -o out.epub part1.md part2.md --title "Report"
"${CLAUDE_SKILL_DIR}/scripts/md2kindle-epub.sh" -o out.epub ballot.md --raw-checkboxes

The wrapper sets --toc --toc-depth=3 --split-level=2 (a real table of contents; chapters split at each ## so no single internal file gets huge) and disables the task_lists extension by default, so GFM checkboxes stay literal [ ] / [x] text instead of HTML <input type="checkbox"> elements. Plain text is guaranteed to survive a server-side ebook conversion; form elements are not. --raw-checkboxes restores native task-list HTML.

Getting the file onto a device is a separate concern — see the send-to-kindle skill for delivery routes, addressing, and size limits.

Man page → Markdown

man pandoc | pandoc -f man -t gfm --wrap=none

Batch conversion

for f in *.docx; do pandoc --extract-media=media/ -o "${f%.docx}.md" "$f"; done

Format Detection

Pandoc auto-detects formats from file extensions. Specify -f/-t explicitly when:

  • Reading from stdin or writing to stdout
  • Extension is ambiguous (e.g., .txt → defaults to markdown)
  • You need a specific variant (gfm vs markdown vs commonmark)

Markdown Variants

FormatUse for
gfmGitHub — tables, task lists, strikethrough, autolinks
commonmarkStrict CommonMark spec
commonmark_xCommonMark + pandoc extensions
markdownPandoc's Markdown — most features, default
markdown_strictOriginal Gruber Markdown — minimal

Listing formats

pandoc --list-input-formats
pandoc --list-output-formats
pandoc --list-extensions=gfm          # extensions for a specific format

Standalone vs Fragment

ModeFlagOutputUse when
Fragment(default)Body content onlyEmbedding in another document
Standalone-sComplete document with headersCreating a valid file (HTML, LaTeX, etc.)

Always use -s for HTML files, LaTeX documents, and slide decks. DOCX/PDF/EPUB are always standalone.

When to Use Pandoc vs Other Tools

TaskToolWhy
Document format conversionpandocBuilt for this — one command
Clean HTML → MarkdownpandocHandles structure well
Complex web scrapingDedicated scraperPandoc needs clean HTML input
PDF text extractionpdftotext, pdfplumberPandoc cannot read PDF
Image format conversionImageMagick, sipsNot pandoc's domain
CSV/JSON data processingjq, csvkit, codePandoc reads CSV/JSON but as documents
Markdown rendering in terminalglow, pandoc -t ansiEither works
Office doc creation (complex)python-docx, openpyxlWhen pandoc's model is too simple

Common Mistakes

MistakeFix
Writing a Python script for DOCX → MDUse pandoc --extract-media=media/ -o out.md in.docx
Forgetting -s for standalone HTMLAdd -s when output needs <head> and <body>
PDF fails — no LaTeX installedInstall texlive/mactex, or use --pdf-engine=typst or weasyprint
Losing images from DOCXAdd --extract-media=media/
Wrong markdown flavor in outputSpecify -t gfm or -t commonmark explicitly
Piping binary formats to stdoutUse -o file.docx — DOCX/PDF/EPUB must write to files
Line wrapping mangles outputAdd --wrap=none to preserve original line breaks
Checkboxes become <input type="checkbox"> in EPUB/HTMLRead with -f markdown-task_lists to keep literal [ ] / [x] text. Pre-converting to Unicode glyphs (☐/☑) does not help — pandoc treats those as task-list markers unconditionally, independent of the extension flag, and still emits <input>

References

Consult for deep dives — these are loaded on demand, not auto-included:

  • ${CLAUDE_SKILL_DIR}/references/pandoc-manual.md — Curated option reference, templates, extensions
  • ${CLAUDE_SKILL_DIR}/references/pandoc-install.md — Installation on macOS, Linux, Docker + PDF engines
  • ${CLAUDE_SKILL_DIR}/references/pandoc-advanced.md — Lua filters, citations, slides, custom writers, EPUB

Bundled Assets

  • ${CLAUDE_SKILL_DIR}/themes/marked-print.css — Compact A4 print stylesheet (9pt body, GitHub-like headings, Japanese + emoji)
  • ${CLAUDE_SKILL_DIR}/scripts/md2pdf-print.sh — Markdown → A4 print PDF via pandoc + headless Chrome
  • ${CLAUDE_SKILL_DIR}/scripts/md2kindle-epub.sh — Markdown → e-reader EPUB (TOC, chapter splitting, literal checkboxes)

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.