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
@BSVogler
Copy link

I downloaded my wiki, "cd" to it, put the makefile there and then "make". I am using Mac 10.9.4:
-- Copying documents and resources...ditto: can't get real path for source 'Assets'
make: *** [cprsrc] Error 1

@abalter
Copy link

abalter commented Apr 28, 2016

Is this a bash script?

bicb199:linux-bootcamp.wiki balter$ bash make
make: line 1: shell: command not found
make: line 1: R:=: command not found
make: line 2: Resources/Markdown.pl: No such file or directory
make: line 10: all:: command not found
make: line 11: BUILD_DIR: command not found
make: line 11: PDF_OUTPUT: command not found
make: line 11: @echo: command not found
make: line 13: cprsrc:: command not found
make: line 14: @echo: command not found
make: line 15: TEMP_DIR: command not found
make: line 15: @ditto: command not found
make: line 16: TEMP_DIR: command not found
make: line 16: @ditto: command not found
make: line 17: @echo: command not found
make: line 19: convert:: command not found
make: line 21: concat:: command not found
make: line 22: @echo: command not found
make: line 23: TEMP_DIR: command not found
make: line 23: TEMP_DIR: command not found
make: line 23: MD_OUTPUT: command not found
make: line 23: TEMP_DIR: command not found
make: line 23: MD_OUTPUT: command not found
make: line 23: /: Is a directory
make: line 24: @echo: command not found
make: line 26: md2html:: command not found
make: line 27: @echo: command not found
make: line 28: MARKDOWN: command not found
make: line 28: TEMP_DIR: command not found
make: line 28: COVER: command not found
make: line 28: TEMP_DIR: command not found
make: line 28: COVER: command not found
make: line 28: TEMP_DIR: command not found
make: line 28: COVER: command not found
make: line 28: /.html: Permission denied
make: line 29: MARKDOWN: command not found
make: line 29: TEMP_DIR: command not found
make: line 29: MD_OUTPUT: command not found
make: line 29: TEMP_DIR: command not found
make: line 29: HTML_OUTPUT: command not found
make: line 29: TEMP_DIR: command not found
make: line 29: HTML_OUTPUT: command not found
make: line 29: /: Is a directory
make: line 30: @echo: command not found
make: line 32: html2pdf:: command not found
make: line 33: @echo: command not found
make: line 35: WKHTMLTOPDF: command not found
make: line 35: TEMP_DIR: command not found
make: line 35: COVER: command not found
make: line 35: TEMP_DIR: command not found
make: line 35: HTML_OUTPUT: command not found
make: line 35: BUILD_DIR: command not found
make: line 35: PDF_OUTPUT: command not found
make: line 35: @: command not found
make: line 49: clean:: command not found
make: line 50: TEMP_DIR: command not found
make: line 50: @rm: command not found
make: line 52: test:: command not found
make: line 53: BUILD_DIR: command not found
make: line 53: PDF_OUTPUT: command not found
make: line 53: @open: command not found
make: line 55: .PHONY:: command not found
bicb199:linux-bootcamp.wiki balter$ 

@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