Convert between several markup formats with Pandoc
Pandoc is a command-line tool for converting from one markup format to another: Markdown, HTML, LaTeX, DOCX, etc.
Table of Contents
Installation
pandoc
is likely installed on your system, but if it’s not, you can easily install it with your operating system’s package manager.
Basic usage
Pandoc syntax is simple:
pandoc [<options>] <input file>
- If no input files are specified,
pandoc
reads from standard input (‘stdin’). - Output goes to stdout by default.
- Format of the input and output files are guessed based on files’ extensions, unless explicitly specified.
Options
-o <file>
: specify an output file.-f <format>
: specify a format for the input file.-t <format>
: specify a format for the output file.-s
: produce a ‘standalone’ document (e.g.: a valid HTML file with the<head>
and<body>
tags) instead of a document fragment.
Run pandoc --list-input-formats
and pandoc --list-output-formats
to print a list of supported formats.
Examples
You can do a lot of markup and file conversions with pandoc. Check its man page for more info (man pandoc
). These are some examples with Markdown:
Markdown to HTML
pandoc -s -o output.html markdown.md
HTML to Markdown
pandoc -o web.md index.html
Markdown to manual page
- Check the result before saving
pandoc -s -t man mycommand.md | man -l -
- Save the manpage
pandoc -s -t man mycommand.md -o mycommand
Markdown file must follow this syntax:
% COMMAND(1)
% John Doe
% January 2023
# NAME
command - my new command
# SYNOPSIS
`command [-t <type>] <file>`
# DESCRIPTION
My awesome command can do a lot of things.
# OPTIONS
`-t <type>` : specify a type
Markdown to PDF
pandoc -o output.pdf markdown.md
- Pandoc cannot convert from PDF to other format.
More
Convert between CSV-JSON, TXT-ODT/DOCX, Markdown-EPUB, HTML-PDF and much more, with the same syntax. Check pandoc manual page and the website (https://pandoc.org/).
If you have any suggestion, feel free to contact me via social media or email.
Latest tutorials and articles:
Featured content: