-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmd2confluence_gnuSed.sh
executable file
·54 lines (33 loc) · 1.1 KB
/
md2confluence_gnuSed.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
#!/bin/bash
# ---------------------- replace head ----------------------
h5="h5. "
h4="h4. "
h3="h3. "
h2="h2. "
h1="h1. "
sed -i "s/^#####\( \)/${h5}/" ${1}
sed -i "s/^####\( \)/${h4}/" ${1}
sed -i "s/^###\( \)/${h3}/" ${1}
sed -i "s/^##\( \)/${h2}/" ${1}
sed -i "/${h2}/a ----" ${1}
sed -i "s/^#\( \)/${h1}/" ${1}
sed -i "/${h1}/a ----" ${1}
# ---------------------- replace list ----------------------
l2="-- "
l3="--- "
l4="---- "
sed -i "s/ - /${l4}/" ${1}
sed -i "s/ - /${l3}/" ${1}
sed -i "s/ - /${l2}/" ${1}
# ---------------------- replace bold ----------------------
sed -i "s/\`/\*/g" ${1}
sed -i "s/\*\*/\*/g" ${1}
# ---------------------- replace link ----------------------
sed -i "/\:\/\//{ s/)/\]/ }" ${1}
sed -i "/\:\/\//{ s/\](/\|/ }" ${1}
# ---------------------- replace task ----------------------
sed -i "s/\- \[.\]/\-\- []/g" ${1}
# ---------------------- not modify below ----------------------
# Because there may be one or more # in one line, like ### or #####
# we need to substitute the # according to the order from most to least
# to avoid the wrong substitution like ####h1.