Makefile for Pandoc: Markdown to HTML

Step-by-Step descriptions of how to do things.

Makefile for Pandoc: Markdown to HTML

Postby peter_b » Sat Sep 30, 2017 2:22 am

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.
  • 0

User avatar
peter_b
Chatterbox
 
Posts: 302
Joined: Tue Nov 12, 2013 2:05 am
Reputation: 3

Return to HowTo's

Who is online

Users browsing this forum: No registered users and 1 guest

Who is online over last 24 hours

Users browsed this forum in the last 24 hours: No registered users and 18 guests

cron
Reputation System ©'