Page 1 of 1

Makefile for Pandoc: Markdown to HTML

Posted: Sat Sep 30, 2017 2:22 am
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.