forked from androportal/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml2sphinx.sh
83 lines (72 loc) · 1.6 KB
/
html2sphinx.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
#!/bin/bash
# htm2sphinx.sh
# --------------------
# -bash sript which helps to converts html pages to rst (sphinx) format
# recursively, including index.rst
# -requires `html2rest`
# --------------------
function convert() {
# ----
# wil convert html to rst using `html2rest
# <http://pypi.python.org/pypi/html2rest/>`_
# ----
FILE=$(find -type f -iname "*.htm")
# echo $FILE
for f in ${FILE[@]}
do
# echo $f
RST=$(echo $f | sed 's/.htm/.rst/g')
# echo $RST
html2rest $f > $RST
done
}
function reSt() {
# ----
# find .rst files(recursively) and edit it to the format
# required by sphinx
# ----
DIR=$(find -maxdepth 1 -type d -iname "*" -not -iname ".")
# echo $DIR
for d in ${DIR[@]}
do
echo -e "$d"
DIR_NAME=$(echo $d | sed 's$./$$g')
echo " ${DIR_NAME}" >> index
echo "====" > ${DIR_NAME}.rst
echo "$DIR_NAME" >> ${DIR_NAME}.rst
echo "====" >> ${DIR_NAME}.rst
cat content >> ${DIR_NAME}.rst
find -type f -iname "*.rst" | \
sed 's$^./$$g' | \
sed 's/.rst//g' | \
sed 's/^/ /g' | \
grep "${DIR_NAME}" >> ${DIR_NAME}.rst
cd $d
RST_FILE=$(find -type f -iname "*.rst")
for f in ${RST_FILE[@]}
do
HEADING=$(echo $f | sed 's$./$$g' | sed 's/.rst//g')
# echo $HEADING
sed -i '1i ====\n"'${HEADING}'"\n====\n' $f
done
cd ..
done
}
# _init__
convert
reSt
# --------------------
# BUGS
#
# 1)
# =========
# some_name
# =========
#
# 2)
# circular toctree detected
#
# 3)
# mtlb/Matlab-Scilab_character_strings in /string/
#
# --------------------