-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.sh
executable file
·95 lines (85 loc) · 2.79 KB
/
convert.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
93
94
95
#!/bin/bash
# ==============================================================================
# "docs-src/convert.sh" v1.0.0 | 2020/08/20 | by Tristano Ajmone
# Released into the Public Domain (https://unlicense.org)
# ------------------------------------------------------------------------------
# Unified Polygen Docs conversion script supporting all documents locales.
# Invoke passing either a supported locale or "all" (to build all docs):
#
# convert.sh <all|en|it>
#
# Parameters are case-insensitive.
# ==============================================================================
function showhelp() {
echo -e "\e[37;1mThis script requires one parameter (either a supported locale or \"all\"):\n"
echo -e "\e[37;1m convert.sh <all|en|it>\e[0m"
}
function finished() {
echo -e "\e[30;1m------------------------------------------------------------------------------"
echo -e "\e[32;1m/// CONVERSION FINISHED ///\n\e[0m"
}
function convert() {
echo -e "\e[30;1m------------------------------------------------------------------------------"
echo -e "\e[34;1mNow converting: \e[33;1m$1\e[0m"
pp -import=assets/macros.pp \
$1 \
| pandoc \
-F pandoc-crossref \
-F pandoc-citeproc \
-f markdown \
-t html5 \
--template=assets/GitHub.html5 \
--toc \
--toc-depth=5 \
--self-contained \
-o ${1%.*}.html
}
# Initialize working environment:
# ===============================
source ./init.sh
# Abort if no parameter was found:
# ================================
if [ $# -eq 0 ]; then
echo -e "\e[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\e[31;1m*** ERROR *** Required parameter missing!"
echo -e "\e[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
showhelp
exit 1
fi
# Issue warning for extra parameters:
# ===================================
if [ $# -gt 1 ]; then
echo -e "\e[33;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\e[33;1m*** WARNING *** More than one parameter!"
echo -e "\e[33;1mExtra parameter(s) will be ignored."
echo -e "\e[33;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
fi
param=$(echo $1 | tr '[:upper:]' '[:lower:]')
nomatch=maybe
case $param in
en) echo -e "\e[34;1mConverting English document:"
convert "polygen-spec_EN.markdown"
finished
unset nomatch
;;
it) echo -e "\e[34;1mConverting Italian document:"
convert "polygen-spec_IT.markdown"
finished
unset nomatch
;;
all) echo -e "\e[34;1mConverting documents of every locale:"
convert "polygen-spec_EN.markdown"
convert "polygen-spec_IT.markdown"
finished
unset nomatch
;;
esac
# Handle invalid parameter error:
# ===============================
if [ $nomatch ]; then
echo -e "\e[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "\e[31;1m*** ERROR *** Invalid parameter: \e[33;1m$param"
echo -e "\e[31;1m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\e[0m"
showhelp
exit 1
fi