-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc
executable file
·70 lines (59 loc) · 1.88 KB
/
doc
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
#!/bin/bash -e
# Builds HTML output from Markdown file.
KEEP="no"
usage() {
(
echo "usage: ${0##*/} [-h|--help|-k] FILE.md"
echo "Opens FILE.md as FILE.html in your default web browser."
echo
echo "$(tput bold)Requires pandoc, pandoc-sidenote, tufte-css, and tufte-pandoc-css:$(tput sgr0)"
echo
echo " $ cd ~"
echo " $ brew install pandoc"
echo " $ brew install jez/formulae/pandoc-sidenote"
echo " $ git clone https://github.com/edwardtufte/tufte-css.git .tufte-css"
echo " $ git clone https://github.com/jez/tufte-pandoc-css.git .tufte-pandoc-css"
echo
echo "options:"
(
echo " -h, --help@ show usage help"
echo " -k@ keep .html artifact (default: $KEEP)"
) | column -ts@
) >&2
exit 1
}
if echo "$*" | grep -Eq -- '--help\b|-h\b' || [[ -z $1 ]]; then
usage
fi
# shellcheck source=.shell_control
# shellcheck disable=SC1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
while getopts "k" opt; do
case "$opt" in
k) KEEP="yes" ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
SRC="$(realpath "$1")"
TGT="$(dirname "$SRC")/$(basename "$1" .md).html"
run "cd '$HOME/.tufte-pandoc-css'" || usage
CMD="pandoc '$SRC'"
CMD="$CMD --katex"
CMD="$CMD --section-divs"
CMD="$CMD --from markdown+tex_math_single_backslash"
CMD="$CMD --filter pandoc-sidenote"
CMD="$CMD --to html5"
CMD="$CMD --template=tufte"
CMD="$CMD --css ~/.tufte-css/tufte.css"
CMD="$CMD --css ~/.tufte-pandoc-css/pandoc.css"
CMD="$CMD --css ~/.tufte-pandoc-css/pandoc-solarized.css"
CMD="$CMD --css ~/.tufte-pandoc-css/tufte-extra.css"
CMD="$CMD --output '$TGT'"
run "$CMD" || usage
open "$TGT"
if [[ $KEEP == "no" ]]; then
run "sleep 1"
run "rm '$TGT'"
show -i "use -k to keep .html file"
fi