-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmd_pdfmaker
executable file
·57 lines (51 loc) · 1.61 KB
/
md_pdfmaker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Make PDF file(s) from docs/simdocs/ .md files
# Defaults to all, or specify filename(s)
#
# Note that the PDF document title comes from the first line of the MD
function dopdf () {
local IN="$(basename $1 ".md")"
if ! [[ "$IN" =~ _doc$ ]]; then
IN="${IN}_doc"
fi
if ! [[ "$IN" =~ \.md$ ]]; then
IN="${IN}.md"
fi
local R="$(readlink -nf "$IN")"
[ -n "$R" ] && IN="$R"
local ON="$(dirname "$1")/$(basename "$IN" ".md").pdf"
echo "$IN => $(basename $ON)"
# Generating PDF with working internal links requires
# - No Unicode chars (checkmark = ✓), ǂ = ≠ ࣔ
# - LaTex processor (html handles Unicode, but not links)
# This work-around seems OK, at least for hp2100, for now.
# Remove <!-- notpdf --> blocks (replaced with yaml meta
# block's data in PDF generation
if ! [ -f "$IN" ]; then
echo "${IN}: no such file"
return
fi
mkdir -p /tmp/pdfmaker
trap "rm -rf /tmp/pdfmaker" EXIT INT
if [ "$IN" -nt "$ON" ] || [ "$ME" -nt "$ON" ]; then
IN="$(basename "$IN")"
echo " - Updating"
LANG=en_US.UTF-8 sed -e's/✓/Y/g;s/ǂ/\/=/g;/^<!-- notpdf -->/,/^<!-- \/notpdf -->/d;' "${IN}" >/tmp/pdfmaker/${IN}
pandoc "/tmp/pdfmaker/${IN}" -o "$ON" \
|| exit 97
else
echo " - Already up to date"
fi
}
ME="$(readlink -e $0)"
[ -z "$ME" ] && exit 90
cd "$(dirname "$0")/docs/simdocs" || exit 99
if [ -n "$1" ]; then
while true; do
[ -z "$1" ] && exit
dopdf "$1";
shift
done
exit
fi
for F in *_doc.md; do dopdf "$F"; done