pandoc: Markdown to HTML and docx
pandoc doc.md -s -o doc.html and pandoc doc.md -o doc.docx convert Markdown to standalone HTML or a Word document without any external engine.
Unlike PDF, HTML and docx output need no LaTeX, so these conversions are dependency-light and reliable in CI. The flags worth knowing are -s for standalone and --reference-doc for docx styling.
What it does
pandoc reads the input format and writes the output format inferred from the -o extension (or forced with -t). -s (standalone) wraps HTML output in a full document with <head>; for docx, --reference-doc supplies a template Word file whose styles pandoc reuses.
Common usage
# standalone HTML with a CSS file
pandoc doc.md -s --css=style.css -o doc.html
# Word document
pandoc doc.md -o doc.docx
# docx using a styled reference template
pandoc doc.md --reference-doc=template.docx -o doc.docx
# self-contained HTML (embed images/CSS)
pandoc doc.md -s --embed-resources -o doc.htmlOptions
| Flag | What it does |
|---|---|
| -s / --standalone | Produce a full document, not a fragment |
| -o <file> | Output file; extension picks the format |
| -t <format> | Force output format: html, html5, docx, gfm, ... |
| --css=<file> | Link a stylesheet (HTML output) |
| --embed-resources | Inline images, CSS, fonts (self-contained HTML) |
| --reference-doc=<file> | Style template for docx/odt output |
In CI
HTML and docx need no TeX, so use them in pipelines where you want artifacts without installing LaTeX. For consistent corporate styling, commit a template.docx and pass --reference-doc. Generate the reference template once with pandoc -o template.docx --print-default-data-file reference.docx.
Common errors in CI
"pandoc: Could not find data file ... reference.docx" or "--reference-doc: openBinaryFile: does not exist" means the template path is wrong. "Unknown output format" means a typo in -t or an extension pandoc does not recognize. An HTML file that opens blank usually means you omitted -s, producing a bare fragment. "pandoc: command not found" means pandoc is not installed.