2018-06-12 Markdown to PDF

So I’m trying to move my list of spellcasters into a repository where I can start working on a PDF of sorts. I already knew that I didn’t want to try Pandoc. So here we are.

list of spellcasters

try Pandoc

@mathieu suggested WeasyPrint. It converts HTML to PDF. It’s written in Python and I prefer that to the node module markdown-pdf. When I tried markdown-pdf, I had no access to the intermediary HTML and thus I didn’t know where to start when I tried writing a CSS for it.

@mathieu

WeasyPrint

markdown-pdf

So now I’m using WeasyPrint and that means I need a Markdown to HTML processor. Python already comes with Markdown and I just used it, yesterday. Perfect!

Markdown

used it

And now in my Makefile:

%.pdf: %.html
	weasyprint {body}lt; $@

%.html: %.md
	python3 -m markdown --extension=markdown.extensions.tables --file=$@ {body}lt;

I haven’t looked at fiddling with the CSS, though. I’m just happy that I access to the intermediary HTML file.

​#Markdown

Comments

(Please contact me if you want to remove your comment.)

PDF files:

https://alexschroeder.ch/pdfs/spellcasters/

– Alex Schroeder 2018-06-14 13:15 UTC

---

These days it’s a bit more involved. This is from the Just Halberds Makefile. What it does is this:

Just Halberds

1. take `Just-Halberds.md` and turn it into `Just-Halberds.html.tmp` using Python’s markdown module

2. concatenate `Just-Halberds-prefix`, `Just-Halberds.html.tmp`, and `suffix` into `Just-Halberds.html`

3. take `Just-Halberds.html` and `Just-Halberds.css` and turn it into `Just-Halberds.pdf`

The CSS is mentioned in the prefix, where we add the beginning of the HTML file:

<!doctype html>
<html lang=en>
  <head>
    <meta charset="utf-8"/>
    <link type="text/css" rel="stylesheet" href="Just-Halberds.css"/>
  </head>
  <body>

The suffix simply closes those tags again:

</body>
</html>

And this is the Makefile:

all: Just-Halberds.pdf

clean:
	rm -f *.html *.pdf

upload: Just-Halberds.pdf
	rsync -ai $^ sibirocobombus:alexschroeder.ch/pdfs/

%.pdf: %.html %.css
	weasyprint {body}lt; $@

%.html: %-prefix %.html.tmp suffix
	cat $^ > $@

%.html.tmp: %.md
	python3 -m markdown \
		--extension=markdown.extensions.tables \
		--extension markdown.extensions.smarty \
		--extension markdown.extensions.attr_list \
		--file=$@ {body}lt;

– Alex Schroeder 2020-04-15 06:54 UTC