Makefile for Pandoc: Markdown to HTML

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
Posts: 331
Joined: Tue Nov 12, 2013 2:05 am

Makefile for Pandoc: Markdown to HTML

Post by peter_b »

This HowTo mainly consists of a Makefile that can be used to convert multiple Markdown (.md) textfiles to HTML using Pandoc (on Linux).
You simply create and edit Markdown textfiles and when you're ready to publish them on the web, tell "GNU make" to compile all of them to HTML:

Code: Select all

$ make
This is equivalent to "$ make all".

Here's the Makefile for this:

Code: Select all

PD = pandoc
SRC = $(wildcard *.md)
HTML = $(
OUT = ../

all: clean $(HTML)

        $(PD) -so $@ $<
        echo mv $@ $(OUT)$@

        rm -f *.html
It looks for "*.md" and then calls the "%.html" target rule which calls Pandoc for the Markdown source and then moves the resulting file to the directory defined in "$(OUT)".

Thanks to Niko Heikkilä's example code.
Post Reply