Converting Markdown Files with Command-Line Tools on macOS Tahoe
macOS Tahoe provides several command-line tools for converting Markdown (.md) files to other formats, such as HTML or PDF. This guide introduces some common options.
1. Pandoc
Pandoc is the "swiss army knife" of document conversion, supporting a vast range of input and output formats.
Installation
If you don't have Pandoc installed, you can download it from https://pandoc.org/installing.html or use Homebrew:
brew install pandoc
Usage
-
Markdown to HTML:
pandoc input.md -o output.html -
Markdown to PDF:
pandoc input.md -o output.pdf
2. mdcat
mdcat is useful for displaying Markdown in the terminal with syntax highlighting, but it can also convert to HTML.
Installation
You can install mdcat using Homebrew:
brew install mdcat
Usage
-
Markdown to HTML:
mdcat input.md > output.html
3. cmark
cmark is CommonMark's reference implementation in C. It's fast and accurate, but it only converts to HTML.
Usage
-
Markdown to HTML:
cmark input.md > output.html
4. wkhtmltopdf
wkhtmltopdf is not strictly a Markdown converter; it renders HTML into PDF. Therefore, you typically combine it with Pandoc.
Installation
You can install wkhtmltopdf using Homebrew:
brew install wkhtmltopdf
Usage
-
Markdown to PDF (using Pandoc and wkhtmltopdf):
pandoc input.md -o output.html wkhtmltopdf output.html output.pdf