-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd2pdf
executable file
·93 lines (74 loc) · 1.49 KB
/
md2pdf
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
templates_location=~/.md2doc
verbose=false
usage() {
echo $1
cat << EOUSAGE
usage: $0 command [args]
where command is one of
- list-inputs: show available input files for debugging
- list-templates: show available templates
- pdf <input markdown file> [template]
- help: to get this help
EOUSAGE
exit 0
}
run() {
if [[ "${verbose}" = true ]]; then
echo running $@
fi
$@
}
template_path() {
template_name=$1
echo ${templates_location}/${template_name}/template.tex
}
background_path() {
template_name=$1
echo ${templates_location}/${template_name}/multibackground.pdf
}
convert_pdf() {
template_name=${2:-default}
input_file_name=$1
if [[ "${input_file_name}" == "" ]]; then
usage "missing input markdown file"
fi
output_file_name=$(basename ${input_file_name} .md).pdf
temp_file=$(mktemp).pdf
run pandoc --template=$(template_path ${template_name}) ${input_file_name} -o ${temp_file}
run pdftk ${temp_file} multibackground $(background_path ${template_name}) output ${output_file_name}
rm ${temp_file}
}
case $1 in
"--verbose")
shift
verbose=true
;;
esac
command=$1
case "$command" in
"")
usage "command missing"
;;
"pdf")
shift
convert_pdf $@
;;
"list-templates")
shift
echo "Templates are in ${templates_location}"
ls ${templates_location}
;;
"list-inputs")
shift
echo "Inputs are in $(pwd)"
ls
;;
"help")
usage
;;
*)
usage
;;
esac