Skip to content

Instantly share code, notes, and snippets.

@bmmalone
Created March 9, 2017 09:06
Show Gist options
  • Save bmmalone/5162254edda514bd6331af75b97c8656 to your computer and use it in GitHub Desktop.
Save bmmalone/5162254edda514bd6331af75b97c8656 to your computer and use it in GitHub Desktop.
Makefile to use pandoc to convert all markdown files to html and pdf
# Makefile
#
# Converts Markdown to other formats (HTML, PDF) using Pandoc
# <http://johnmacfarlane.net/pandoc/>
#
# Run "make" (or "make all") to convert to all other formats
#
# Run "make clean" to delete converted files
#
# Adapted from: https://gist.github.com/kristopherjohnson/7466917
# Convert all files in this directory that have a .md suffix
SOURCE_DOCS := $(wildcard *.md)
EXPORTED_DOCS=\
$(SOURCE_DOCS:.md=.html) \
$(SOURCE_DOCS:.md=.pdf) \
RM=/bin/rm
PANDOC=pandoc
PANDOC_OPTIONS=--smart --standalone
PANDOC_HTML_OPTIONS=--to html5
PANDOC_PDF_OPTIONS=
# Pattern-matching Rules
%.html : %.md
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_HTML_OPTIONS) -o $@ $<
sed -i 's:\.md:.html:g' $@
%.pdf : %.md
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_PDF_OPTIONS) -o $@ $<
# Targets and dependencies
.PHONY: all clean
all : $(EXPORTED_DOCS)
clean:
- $(RM) $(EXPORTED_DOCS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment