-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdz.sh
92 lines (82 loc) · 1.98 KB
/
markdz.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
87
88
89
90
91
92
#!/bin/bash
# check for enhanced getopt and quit otherwise
# any modern linux and CYGWIN will have enhanced getopt
# however, it's not the default on osx and has to be installed
getopt --test
if [[ $? -ne 4 ]]; then
echo "Enhanced getopt not found"
exit 1
fi
# set default values
outfile="readme.html"
infile="README.md"
tocDepth=3
tocOnly=0
# set options for getopt
shortOps=o:ti:v
longOps=output:,toc,input:,toc-depth:,verbose,toc-only
options=$(getopt --options $shortOps --longoptions $longOps --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
exit 2
fi
eval set -- "$options"
while true; do
case "$1" in
-o|--output)
outfile="$2"
shift 2
;;
-t|--toc)
toc="--toc"
shift
;;
-i|--input)
infile="$2"
shift 2
;;
--toc-depth)
tocDepth="$2"
shift 2
;;
--toc-only)
tocOnly=1
echo "TOC only is not implemented yet"
shift
;;
-v|--verbose)
printOptions=1
shift
;;
--)
shift
break
;;
*)
echo "Unknown implementation error. This shouldn't happen."
exit 3
;;
esac
done
cssLocation=$(dirname $0)
if [[ $printOptions -eq 1 ]]; then
echo outfile = $outfile
echo infile = $infile
echo tocDepth = $tocDepth
echo tocOnly = $tocOnly
echo toc = $toc
echo cssLocation = $cssLocation/github.css
fi
# if creating markdown file, always generate github markdown
# remove hard line breaks to mimik github
if [[ "$outfile" == *.md ]]; then
markdownFormat="--to=markdown_github-hard_line_breaks"
fi
pandoc \
-o $outfile \
--from=markdown_github-hard_line_breaks \
${markdownFormat:+"$markdownFormat"} \
--css $cssLocation/github.css \
--self-contained \
${toc:+"$toc"} \
--toc-depth=$tocDepth \
$infile