Convert Markdown to HTML:
Browse / Pandoc Document Conversion Cheatsheet
Pandoc Document Conversion Cheatsheet
A quick reference guide for Pandoc, the universal document converter. Covers basic syntax, common options, markdown extensions, and useful tips for converting documents between various formats.
Core Usage & Basics
Basic Conversion Syntax
|
|
|
|
Convert HTML to Markdown: |
|
|
Convert Markdown to PDF (requires LaTeX): |
|
|
Convert Markdown to DOCX: |
|
|
Specify input and output formats explicitly: |
|
|
Convert from stdin to stdout: |
|
|
Convert multiple input files: |
|
|
Convert from a URL: |
|
Basic Metadata & Options
|
|
Produce a standalone document (with header and footer). Example:
|
|
|
Add metadata. Can be used multiple times. Example:
|
|
|
Read metadata from a YAML file. Example:
meta.yaml:
|
|
|
Include an automatically generated table of contents. Example:
|
|
|
Number section headings in the output. Example:
|
|
|
Set template variables. Useful for customizing output templates. Example:
|
|
|
Link to a CSS file in HTML output. Example:
|
Input/Output Formats (-f, -t)
|
Common Input Formats ( |
|
|
Common Output Formats ( |
|
|
List all supported formats: |
|
|
Use format extensions (e.g., |
Extensions enable/disable specific features. Use Example:
|
|
Convert to HTML with specific extensions: |
|
|
Convert to PDF using |
|
|
Convert to DOCX with a reference document: |
(Template DOCX controls styles) |
|
Convert to HTML using a custom template: |
(Templates control the overall document structure) |
Markdown Extensions & Content
Tables
|
Pipe Tables: Simple syntax, requires header and separator line. Align with colons.
|
|
Pipe Table Alignment:
|
|
Simple Tables: More flexible, no pipes needed. Requires blank lines before and after.
|
|
Simple Table Alignment: Determined by the colon placement in the separator line.
|
|
Grid Tables: Full features (multi-line cells, row/col spans). More complex.
|
|
Enable grid tables explicitly if needed:
|
|
Compact tables (for simple 2-column data):
|
Code Blocks & Highlighting
|
Fenced Code Blocks: Use triple backticks or tildes. Add language identifier for highlighting.
|
|
Indented Code Blocks: Indent lines by 4 spaces or 1 tab. No language highlighting.
|
|
Inline Code: Use single backticks.
|
|
Syntax Highlighting: Example (with language):
Example (no language):
|
|
Disable highlighting:
|
|
List available highlighting styles:
|
|
Apply a specific highlighting style:
|
|
Create a custom highlighting style (usually requires dumping default style and editing). |
Lists & Definition Lists
|
Bulleted Lists: Use
|
|
Ordered Lists: Use numbers followed by a period or parenthesis.
|
|
Definition Lists: Term on a line, definition indented on the next line(s).
|
|
Pandoc supports various list markers (e.g., |
|
Lists can contain multiple paragraphs, code blocks, etc., by indenting everything belonging to the list item. |
|
Example of list with multiple blocks:
|
|
Ensure blank lines between list items if they contain multiple paragraphs or blocks. |
Images, Links, & Footnotes
|
Inline Images:
|
|
Reference Images:
|
|
Inline Links:
|
|
Reference Links:
|
|
Automatic Links: URLs in angle brackets
|
|
Footnotes: Place
|
|
Use
|
Advanced Features & Tips
Citations and Bibliography
|
Pandoc can automatically generate citations and a bibliography from various formats (BibTeX, CSL-JSON, etc.) using a Citation Style Language (CSL) file. |
|
Required options: Example:
|
|
Place citations using keys from your bibliography file, enclosed in square brackets and prefixed with Example Markdown:
|
|
The bibliography will be inserted automatically at the end of the document where a section titled “Bibliography” or “References” (or similar) is found, or appended if no such section exists. |
|
Common bibliography formats: |
|
Find CSL styles: |
|
Using a
|
Filters (Lua)
|
Filters are programs that can read the pandoc Abstract Syntax Tree (AST) in JSON format, modify it, and write it back out. Lua filters are powerful and easy to use. |
|
Use the Example:
|
|
A simple Lua filter to change all emphasis (
|
|
Filters can inspect and modify any element in the AST (paragraphs, headings, links, images, etc.). |
|
Multiple filters can be applied by listing them sequentially:
|
|
Explore the Pandoc documentation for the full AST structure and examples of more complex filters. |
|
Filters are useful for:
|
Useful Tips & Tricks
|
Debug AST: |
Convert to JSON format to inspect the intermediate representation:
|
|
Get default template: |
Dump the default template for a specific format to customize it:
|
|
Include raw content (e.g., LaTeX in Markdown): |
Use raw attribute blocks.
|
|
Convert directory of files: |
Use shell scripting to process multiple files.
|
|
Processing front-matter: |
Pandoc reads YAML metadata blocks at the start of the document.
|
|
Convert Markdown to PDF with custom margins (using LaTeX variables): |
|
|
Using includes: |
Include headers, before/after body content in LaTeX/PDF output.
|
|
Adding classes/IDs to elements: |
Use curly braces
|
Troubleshooting & Help
|
Check Pandoc version: |
|
|
Get help on options: |
|
|
Check for required dependencies (e.g., LaTeX for PDF, citeproc for citations, highlighting-kate for highlighting). |
|
Common PDF issues often stem from missing LaTeX packages. Pandoc usually tells you which one is missing. |
|
Complex conversions or template issues can often be debugged by converting to the intermediate JSON AST ( |
|
Consult the official Pandoc User’s Guide online for the most comprehensive information and advanced features. |