-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_docs.py
78 lines (61 loc) · 2.21 KB
/
build_docs.py
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
import os
from emtools.utils import Process, Color
def main():
Process.system("rm -rf html", color=Color.green)
Process.system("sphinx-build -b html docs html", color=Color.green)
Process.system("sphinx-build -b html docs/js html/js", color=Color.green)
replace_content()
def replace_content():
# Replace the article from: html/developer_guide/api/javascript.html
# with the one here: html/js/index.html
article_lines = []
ref_lines = []
in_article = False
in_toc = False
toc_lines = []
js_index = 'html/js/index.html'
if not os.path.exists(js_index):
print(f"Missing file {js_index}, skipping.")
return
with open(js_index) as f:
print(f"Parsing {Color.bold(js_index)}")
for line in f:
if '<article' in line:
in_article = True
elif 'article>' in line:
in_article = False
elif '<aside class="toc-drawer">' in line:
in_toc = True
elif '</aside>' in line:
in_toc = False
else:
if in_article:
article_lines.append(line)
elif in_toc:
toc_lines.append(line)
all_lines = []
in_toc = in_article = False
js_file = 'html/developer_guide/api/javascript.html'
with open(js_file) as f:
print(f"Parsing {Color.bold(js_file)}")
for line in f:
if '<article' in line:
all_lines.append(line) # article line
all_lines.extend(article_lines)
in_article = True
elif 'article>' in line:
in_article = False
elif '<aside class="toc-drawer">' in line:
all_lines.append(line) # toc line
all_lines.extend(toc_lines)
in_toc = True
elif '</aside>' in line:
in_toc = False
if not in_article and not in_toc:
all_lines.append(line)
with open('html/developer_guide/api/javascript.html', 'w') as f:
for line in all_lines:
f.write(line)
#Process.system("rm -rf html/js", color=Color.green)
if __name__ == '__main__':
main()