Skip to content

Instantly share code, notes, and snippets.

@romac
Created July 15, 2011 13:36
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save romac/1084698 to your computer and use it in GitHub Desktop.
Save romac/1084698 to your computer and use it in GitHub Desktop.
Markdown to PDF
TEMP_DIR:=$(shell mktemp -d -t /tmp)
MARKDOWN=perl Resources/Markdown.pl
WKHTMLTOPDF=/usr/local/bin/wkhtmltopdf
BUILD_DIR=Build
MD_OUTPUT=Documentation.md
HTML_OUTPUT=Documentation.html
PDF_OUTPUT=Documentation.pdf
COVER=__Couverture
all: convert clean
@echo -- The documentation has been successfully generated and can be found in $(BUILD_DIR)/$(PDF_OUTPUT)
cprsrc:
@echo -n -- Copying documents and resources...
@ditto *.md $(TEMP_DIR)/
@ditto Assets $(TEMP_DIR)/Assets
@echo ' Done.'
convert: html2pdf
concat: cprsrc
@echo -n -- Concatenating the Markdown files...
@cat $(TEMP_DIR)/0*.md > $(TEMP_DIR)/$(MD_OUTPUT)
@echo ' Done.'
md2html: concat
@echo -n -- Converting Markdown documents to HTML...
@$(MARKDOWN) $(TEMP_DIR)/$(COVER).md > $(TEMP_DIR)/$(COVER).html
@$(MARKDOWN) $(TEMP_DIR)/$(MD_OUTPUT) > $(TEMP_DIR)/$(HTML_OUTPUT)
@echo ' Done.'
html2pdf: md2html
@echo -- Converting the HTML documents to PDFs...
@$(WKHTMLTOPDF) \
--load-error-handling ignore \
--encoding utf-8 \
--user-style-sheet Resources/Styles.css \
--minimum-font-size 14 \
--footer-left "[date]" \
--footer-right "[page] / [topage]" \
--footer-font-size 10 \
cover $(TEMP_DIR)/$(COVER).html \
toc \
--disable-dotted-lines \
--xsl-style-sheet Resources/TOC.xsl \
$(TEMP_DIR)/$(HTML_OUTPUT) \
$(BUILD_DIR)/$(PDF_OUTPUT)
clean:
@rm -rf $(TEMP_DIR)
test:
@open $(BUILD_DIR)/$(PDF_OUTPUT)
.PHONY: all
@AlexMooney
Copy link

@abalter this is a Makefile; it's meant to be used with Make instead of executed in bash. Check out this article for some motivation Why Use Make.

@zach27
Copy link

zach27 commented Aug 5, 2016

I assume this makefile is for a MAC since it uses ditto? Is there too much to change to convert it to Linux?

@irzhywau
Copy link

perl Resources/Markdown.pl ?? where we can find this code?

@romac
Copy link
Author

romac commented Mar 15, 2023

perl Resources/Markdown.pl ?? where we can find this code?

I don't remember exactly, but it's probably this: https://daringfireball.net/projects/markdown/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment