-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmd2html.py
27 lines (20 loc) · 953 Bytes
/
md2html.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
import os, markdown2
import shutil
docs = os.path.dirname(os.path.abspath(__file__))
repo = os.path.dirname(docs)
# copy images
shutil.rmtree(os.path.join(repo, 'html', 'images'), ignore_errors=True)
shutil.copytree(os.path.join(repo, 'docs', 'images'), os.path.join(repo, 'html', 'images'))
# generate HTML files
template = open(os.path.join(docs, 'template.html'), 'r').read()
for filename, title in [('changelog', 'Changelog'),
('fmu_export', 'FMU Export'),
('fmu_import', 'FMU Import'),
('index', 'FMI Kit' )]:
with open(os.path.join(docs, filename + '.md')) as f:
md = f.read()
html = markdown2.markdown(md, extras=['tables', 'fenced-code-blocks'])
output = template.replace('{{content}}', html)
output = output.replace('{{title}}', title)
with open(os.path.join(repo, 'html', filename + '.html'), 'w') as f:
f.write(output)