-
-
Notifications
You must be signed in to change notification settings - Fork 6
Pandoc Integration
Apex focuses on producing high‑quality HTML. For richer publishing targets like DOCX, PDF, RTF, OPML, ODT, and more, you can combine Apex with Pandoc by piping Apex’s HTML output into Pandoc.
The general pattern is:
apex input.md --standalone | pandoc -f html -t FORMAT -o output.FILE-
--standalonetells Apex to generate a full HTML5 document (<html>,<head>,<body>). -
-f htmltells Pandoc to read HTML. -
-t FORMATand-o output.FILEselect Pandoc’s output format and destination file.
Pandoc must be installed separately (brew install pandoc on macOS, or your platform’s package manager).
Use Pandoc’s DOCX writer to produce Word documents from Apex HTML output:
apex input.md --standalone \
| pandoc -f html -t docx -o output.docxYou can also write the HTML to a file first:
apex input.md --standalone -o output.html
pandoc -f html -t docx output.html -o output.docxTo set the document title from Apex:
apex input.md --standalone --title "My Document" \
| pandoc -f html -t docx -o output.docxPandoc will use the <title> element from the HTML when available.
You can generate PDFs by letting Pandoc handle the PDF engine (usually via LaTeX or a PDF HTML engine, depending on your Pandoc setup):
apex input.md --standalone \
| pandoc -f html -t pdf -o output.pdfWith an explicit title:
apex input.md --standalone --title "My PDF Document" \
| pandoc -f html -t pdf -o output.pdfIf you prefer an intermediate HTML file:
apex input.md --standalone -o output.html
pandoc -f html -t pdf output.html -o output.pdfApex can link or embed a CSS stylesheet in the generated HTML. Pandoc will respect this styling when converting formats that support it (especially PDF via HTML engines, and some DOCX templates).
apex input.md --standalone --style styles.css \
| pandoc -f html -t pdf -o output.pdfThis produces HTML with:
<link rel="stylesheet" href="styles.css">Pandoc uses this when rendering HTML‑based outputs.
To avoid external file dependencies, embed CSS directly:
apex input.md --standalone --style styles.css --embed-css \
| pandoc -f html -t pdf -o output.pdfThis inlines styles.css into a <style> block in the HTML <head>, which is convenient for sharing a single self‑contained document pipeline.
Apex supports metadata via YAML front matter, external metadata files, and --meta CLI flags. This metadata can influence both Apex output and what Pandoc sees.
In your Markdown:
---
title: My Research Paper
author: Jane Example
date: 2024-01-01
---Then:
apex input.md --standalone \
| pandoc -f html -t docx -o output.docxApex will turn this into appropriate HTML metadata (including <title>), which Pandoc can map into the target format’s title and author fields.
You can load shared metadata for multiple documents:
# meta.yml
title: Shared Title
author: Team Apexapex input.md --standalone --meta-file meta.yml \
| pandoc -f html -t pdf -o output.pdfYou can set or override metadata from the command line:
apex input.md --standalone \
| pandoc -f html -t docx -o output.docx \
--metadata=author="Your Name" \
--metadata=subject="Project Report"This lets you mix Apex’s metadata (front matter, --meta-file) with Pandoc’s own metadata flags.
The same pattern works for many other Pandoc targets:
-
RTF
apex input.md --standalone \ | pandoc -f html -t rtf -o output.rtf -
OPML (outline)
apex input.md --standalone \ | pandoc -f html -t opml -o output.opml -
ODT (LibreOffice/OpenOffice)
apex input.md --standalone \ | pandoc -f html -t odt -o output.odt -
EPUB
apex input.md --standalone \ | pandoc -f html -t epub -o output.epub
For a complete pipeline, you can preprocess your Markdown with md-fixup before passing it to Apex:
md-fixup input.md | apex --standalone | pandoc -f html -t docx -o output.docxmd-fixup can fix common Markdown issues and apply search-and-replace transformations before Apex processes the document. See Usage for more details.
By combining Apex and Pandoc, you can keep Apex focused on Markdown parsing and HTML generation while Pandoc handles the heavy lifting for complex document formats.
Copyright 2025 Brett Terpstra, All Rights Reserved | MIT License
- Getting Started - Your first steps with Apex
- Installation - How to build and install Apex
- Usage - Basic usage examples
- Syntax - Complete syntax reference for unified mode
- Callouts - All supported callout formats and flag requirements
- Tables - Complete table syntax reference including rowspan, colspan, alignment, and captions
- Inline Attribute Lists - IALs and ALDs guide with examples
- Modes - Understanding processor modes
-
Quarto Mode - Pandoc/Quarto markdown (
--mode quarto) - Command Line Options - All CLI flags explained
-
Rendering Markdown in the Terminal - Terminal output formats (
-t terminal,-t terminal256),--width,--theme, and theming -
Generating Man Pages - Generate man pages from Markdown using
apex -t man -
Multi-file Documents - Combining multiple files with
--combine,--mmd-merge, and includes - Citations - Citations and bibliography guide
- Indices - Index generation with mmark and TextIndex syntax
-
Metadata Transforms - Transform metadata values with
[%key:transform] - Integrating with Pandoc - Use Apex with Pandoc for DOCX, PDF, and more
- Using Apex with Jekyll - Use the apex-ruby gem as Jekyll’s Markdown converter (untested; feedback welcome)
- Header IDs - How header IDs are generated
- C API - Programmatic API documentation
- Writing Tests - How to add tests for new features
- Xcode Integration - Using Apex in Xcode projects
- Examples - Practical usage examples
- Plugins - Plugin system, examples, and recipes
- Filters - AST filters (Pandoc-style JSON), examples, and usage
- Troubleshooting - Common issues and solutions
- Credits - Acknowledgments and links to related projects