Skip to content
Snippets Groups Projects
Verified Commit bf0a4f30 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Automatically generate print versions from markdown

parent 95c5cb15
Branches
No related tags found
No related merge requests found
/print
File moved
Makefile 0 → 100644
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES := $(wildcard *.md)
OBJECTS := $(addprefix print/,$(SOURCES:%.md=%.pdf))
.PHONY: all
all: $(OBJECTS)
print/%.pdf: %.md meta/header.html meta/wrap_sections.mjs
mkdir -p "$(@D)"
pandoc "$<" -t html -H meta/header.html --filter meta/wrap_sections.mjs -o - | wkhtmltopdf -B 10mm -L 20mm -R 10mm -T 10mm --javascript-delay 0 - "$@"
File moved
File moved
<meta charset="utf-8">
<style>
h1,h2,h3,h4,h5,h6 {
font-family: "Franziska Pro";
font-weight: 400;
}
th {
display: none;
}
:root {
font-family: "Roboto Condensed";
font-weight: 200;
line-height: 1.5;
font-size: 14pt;
}
p, li {
margin-bottom: 0.75rem;
}
td {
font-weight: 200;
font-size: 1rem;
}
body > div > div {
page-break-inside: avoid;
}
div#zutaten table td:first-child {
padding-right: 1rem;
min-width: 6rem;
}
</style>
#!/usr/bin/env node
import readline from "readline";
function groupChildren(blocks, parentLevel) {
const result = [];
while (blocks.length) {
const block = blocks.shift();
if (block.t == "Header") {
const level = block.c[0];
const id = block.c[1][0];
if (parentLevel >= level) {
blocks.unshift(block);
return result;
} else {
const children = groupChildren(blocks, level);
result.push({
"t": "RawBlock",
"c": [
"html",
"<div id=\"" + id + "\">"
]
});
result.push(block);
result.push(...children);
result.push({
"t": "RawBlock",
"c": [
"html",
"</div>"
]
});
}
} else {
result.push(block);
}
}
return result;
}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function (line) {
const data = JSON.parse(line);
const blocks = groupChildren(data.blocks, 0);
console.log(JSON.stringify({
...data,
blocks: blocks
}));
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment