forked from LonamiWebs/Stringlate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-offline-help.py
executable file
·53 lines (42 loc) · 1.17 KB
/
update-offline-help.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
#!/usr/bin/env python3
# Requires markdown (https://python-markdown.github.io/)
#
# Converts the help markdown to HTML and injects the help/style.css
# Used to provide offline help on the application
import os
import markdown
template = \
'''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>{}</style>
</head>
<body>
<article>{}</article>
</body>
</html>
'''
OUT_DIR = './src/app/src/main/res/raw/'
# Load the `help/style.css` to a string
print('Loading style...')
with open('help/style.css', encoding='utf-8') as f:
style = f.read()
# Convert the .md files to HTML
print('Converting .md to .html...')
name_html = []
for md in os.listdir('help'):
if 'index' in md or not md.endswith('.md'):
continue
with open(os.path.join('help', md), encoding='utf-8') as f:
html = markdown.markdown(f.read())
name_html.append(
(os.path.splitext(md)[0] + '.html', template.format(style, html))
)
# Save the HTML files to the .../res/raw/ directory
print('Saving files...')
os.makedirs(OUT_DIR, exist_ok=True)
for name, html in name_html:
with open(os.path.join(OUT_DIR, name), 'w', encoding='utf-8') as f:
f.write(html)