-
Notifications
You must be signed in to change notification settings - Fork 0
/
trans.sh
executable file
·71 lines (58 loc) · 1.69 KB
/
trans.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
#!/usr/bin/env bash
#
# Author: Jake Zimmerman <[email protected]>
#
# A simple script to build an HTML file using Pandoc
#
usage() {
echo "usage: $0 <source.md> <dest.html>"
}
# ----- args and setup -----
src="${1:-}"
dest="${2:-}"
if [ "$src" = "" ] || [ "$dest" = "" ]; then
2>&1 usage
exit 1
fi
case "$src" in
-h|--help)
usage
exit
;;
esac
# ----- main -----
# -c /users/rain/.pandoc/css/dark.css \
# pandoc_template="pandoc \
# --katex \
# --from markdown+tex_math_single_backslash+east_asian_line_breaks \
# --filter pandoc-sidenote \
# --to html5+smart \
# --template=template.html5 \
# -c /Users/rain/.pandoc/css/theme.css \
# -c /Users/rain/.pandoc/css/paper.css \
# -c /users/rain/.pandoc/css/skylighting-gruvbox-theme.css \
# --toc \
# --metadata pagetitle=Wiki \
# --wrap=none"
pandoc_template="pandoc \
--katex \
--from markdown+tex_math_single_backslash+east_asian_line_breaks \
--filter pandoc-sidenote \
--to html5+smart \
--template=template1.html \
-c /Users/rain/.pandoc/css/pandoc.css \
--toc \
--metadata pagetitle=Wiki \
--wrap=none"
dest_dir="$(dirname "$dest")"
mkdir -p "$dest_dir"
# Searches for markdown links (without extension or .md) and appends a .html
# regex1='s/[^!()[]]*(\[[^]]+\])\(([^.)]+)(\.md)?\)/\1(\2.html)/g'
regex1='s/[^!()[]]*(\[[^]]+\])\(([^.)]+)(\.md)?\)/ \1(\2.html)/g'
# [^!\[\])(]*(\[[^\]]+\])\(([^).]+)(\.md)?\)
pandoc_input=$(cat "$src" | sed -r "$regex1")
pandoc_output=$(echo "$pandoc_input" | $pandoc_template)
# POSTPANDOC PROCESSING
# Removes "file" from ![pic of sharks](file:../sharks.jpg)
regex3='s/file://g'
echo "$pandoc_output" | sed -r $regex3 > "$dest"