-
Notifications
You must be signed in to change notification settings - Fork 631
Expand file tree
/
Copy pathmake-html.py
More file actions
executable file
·56 lines (50 loc) · 1.67 KB
/
make-html.py
File metadata and controls
executable file
·56 lines (50 loc) · 1.67 KB
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
#!/usr/bin/env python3
"""Create HTML files of the tutorial."""
import glob
import shutil
import os
import sys
import webbrowser
try:
import mistune
except ImportError:
print("mistune isn't installed. You can install it like this:")
print()
print(">>> import pip")
print(">>> pip.main(['install', '--user', 'mistune'])")
sys.exit(1)
def main():
if os.path.exists('html'):
if input("html exists. Do you want "
"to remove it? [Y/n] ").upper() == 'N':
print("Interrupt.")
return
if os.path.isdir('html'):
shutil.rmtree('html')
else:
os.remove('html')
os.mkdir('html')
print("Generating HTML files...")
for markdownfile in glob.glob('*.md'):
htmlfile = os.path.join('html', markdownfile[:-3] + '.html')
print(' ', markdownfile, '->', htmlfile)
with open(markdownfile, 'r') as f1:
with open(htmlfile, 'w') as f2:
md = f1.read()
md = md.replace('.md)', '.html)')
html = mistune.markdown(md)
print(html, file=f2)
os.rename(os.path.join('html', 'README.html'),
os.path.join('html', 'index.html'))
shutil.copytree('images', os.path.join('html', 'images'))
print()
print("*********************")
print()
print("Ready! The files are in the html directory,")
print("double-click html/index.html to read the tutorial.")
print()
if input("Do you want to view the tutorial now? [Y/n] ").upper() != 'N':
print("Opening the tutorial...")
webbrowser.open(os.path.join('html', 'index.html'))
if __name__ == '__main__':
main()