-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-html.py
66 lines (55 loc) · 1.36 KB
/
build-html.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
import os
import markdown
from markdown.extensions.toc import TocExtension
baseFolder = os.getcwd()
readmePath = os.path.join(baseFolder, 'README.md')
# -------------
# generate html
# -------------
htmlFolder = os.path.join("source", 'html')
htmlPath = os.path.join(htmlFolder, 'index.html')
htmlTemplate = '''\
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CornerTools</title>
<link rel="stylesheet" href="github-markdown.css">
<style>
html {
margin-left: auto;
margin-right: auto;
}
.headerlink {
opacity: 0.0;
}
body h1:hover a.headerlink,
body h2:hover a.headerlink,
body h3:hover a.headerlink,
body h4:hover a.headerlink {
opacity: 1.0;
}
</style>
</head>
<body>
%s
</body>
</html>
'''
with open(readmePath, mode="r", encoding="utf-8") as f:
markdownSource = f.read()
M = markdown.Markdown(extensions=[TocExtension(permalink=True)])
html = htmlTemplate % M.convert(markdownSource)
with open(htmlPath, mode="w", encoding="utf-8") as htmlFile:
htmlFile.write(html)
# -----------
# copy images
# -----------
import shutil
imgsFolder = os.path.join(baseFolder, 'images')
htmlImgsFolder = os.path.join(htmlFolder, 'images')
for f in os.listdir(imgsFolder):
if not os.path.splitext(f)[-1] in ['.png', '.jpg', '.jpeg']:
continue
imgPath = os.path.join(imgsFolder, f)
shutil.copy2(imgPath, htmlImgsFolder)