-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmarkdown-to-pdf.sh
executable file
·86 lines (78 loc) · 1.96 KB
/
markdown-to-pdf.sh
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
#!/bin/bash
# https://github.com/unsignedinteger/deckset-scripts/tree/master/markdown-to-pdf
show_usage() {
echo "Markdown to PDF"
echo ""
echo "Usage: $0 [options] file [file...]"
echo ""
echo "Options:"
echo " -f Overwrite existing output files."
echo " -q quit deckset"
echo " -s Separate slides for all build steps (lists, code highlights)"
echo " -p Include presenter notes"
echo " -h Print usage."
}
OVERWRITE=0
PRINT_ALL_STEPS=false
INCLUDE_PRESENTER_NOTES=false
QUIT=false
while getopts fsqph option
do
case "${option}"
in
f)
OVERWRITE=1;
;;
q)
QUIT=true;
;;
s)
PRINT_ALL_STEPS=true;
;;
p)
INCLUDE_PRESENTER_NOTES=true;
;;
h)
show_usage;
exit 0;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]
then
show_usage
exit 1
fi
for FILE in "$@" ; do
md_file="$(cd "$(dirname "$FILE")"; pwd)/$(basename "$FILE")"
pdf_file="${FILE%.*}.pdf"
if [ ! -e $md_file ]
then
echo "Input file $md_file does not exist!"
exit 2
fi
if [ -e $pdf_file ] && [ $OVERWRITE = 0 ]
then
echo "Error: output file $pdf_file exists. Please use -f option if you want to overwrite it."
exit 3
fi
osascript <<EOF
on run argv
set md_file to "$md_file"
set md_file to POSIX file md_file
set out_file to "$pdf_file"
set out_file to POSIX file out_file
tell application "Deckset"
activate
open file md_file
tell document 1
activate
export to out_file printAllSteps $PRINT_ALL_STEPS includePresenterNotes $INCLUDE_PRESENTER_NOTES
end tell
if $QUIT then
quit
end if
end tell
end run
EOF
done