-
-
Save marekkowalczyk/47625f85c8068d350d0a5342e38b6120 to your computer and use it in GitHub Desktop.
Makefile that uses Pandoc to generate HTML, PDF, DOCX, etc. from Markdown source files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile | |
# | |
# Converts Markdown to other formats (HTML, PDF, DOCX, RTF, ODT, EPUB) using Pandoc | |
# <http://johnmacfarlane.net/pandoc/> | |
# | |
# Run "make" (or "make all") to convert to all other formats | |
# | |
# Run "make clean" to delete converted files | |
# 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) \ | |
$(SOURCE_DOCS:.md=.docx) \ | |
$(SOURCE_DOCS:.md=.rtf) \ | |
$(SOURCE_DOCS:.md=.odt) \ | |
$(SOURCE_DOCS:.md=.epub) | |
RM=/bin/rm | |
PANDOC=/usr/local/bin/pandoc | |
PANDOC_OPTIONS=--smart --standalone | |
PANDOC_HTML_OPTIONS=--to html5 | |
PANDOC_PDF_OPTIONS= | |
PANDOC_DOCX_OPTIONS= | |
PANDOC_RTF_OPTIONS= | |
PANDOC_ODT_OPTIONS= | |
PANDOC_EPUB_OPTIONS=--to epub3 | |
# Pattern-matching Rules | |
%.html : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_HTML_OPTIONS) -o $@ $< | |
%.pdf : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_PDF_OPTIONS) -o $@ $< | |
%.docx : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_DOCX_OPTIONS) -o $@ $< | |
%.rtf : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_RTF_OPTIONS) -o $@ $< | |
%.odt : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_ODT_OPTIONS) -o $@ $< | |
%.epub : %.md | |
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_EPUB_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