Makefile for Pandoc: Markdown to HTML

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
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 = $(SRC:.md=.html)
OUT = ../

all: clean $(HTML)

%.html: %.md
        $(PD) -so $@ $<
        echo mv $@ $(OUT)$@

clean:
        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