forked from LinkClinton/IGP-DirectX12-Chinese
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown-build.py
101 lines (76 loc) · 2.66 KB
/
markdown-build.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import markdown2
def getMathCode(str):
isBegin = False
isDouble = False
mathCode = ""
result = []
for i in range(0, len(str)):
isCurrentEnd = False
if (str[i] is '$'):
if (isBegin is False):
isBegin = True
isDouble = False
else:
if (isDouble is False):
if (str[i-1] is '$'):
isDouble = True
else:
isBegin = False
isDouble = False
isCurrentEnd = True
else:
if (str[i-1] is '$'):
isBegin = False
isDouble = False
isCurrentEnd = True
if (isBegin is True or isCurrentEnd is True):
mathCode += str[i]
if (isCurrentEnd is True):
result.append(mathCode)
mathCode = ""
pass
return result
htmlHead = open("./head.html").read()
buildFile = open("./buildList.txt").readlines()
for item in buildFile:
fileName = item.rstrip('\n')
sourceFile = open(fileName + ".md", encoding = "utf-8").read()
mathCodes = getMathCode(sourceFile)
mathCodeCount = 0
result = htmlHead
html = markdown2.markdown_path(fileName + ".md",
extras=["fenced-code-blocks","code-friendly", "code-color", "tables"])
isBegin = False
isDouble = False
for i in range(0, len(html)):
isCurrentEnd = False
if (html[i] is '$'):
if (isBegin is False):
isBegin = True
isDouble = False
else:
if (isDouble is False):
if (html[i-1] is '$'):
isDouble = True
else:
isBegin = False
isDouble = False
isCurrentEnd = True
else:
if (html[i-1] is '$'):
isBegin = False
isDouble = False
isCurrentEnd = True
if (isBegin is False and isCurrentEnd is False):
result += html[i]
if (isCurrentEnd is True):
result += mathCodes[mathCodeCount]
mathCodeCount += 1
pass
output = open("./" + fileName + ".html", "w" , encoding= "utf-16")
output.write(result)
pass
indexHtml = htmlHead + markdown2.markdown_path("readme.md",
extras=["fenced-code-blocks","code-friendly", "code-color", "tables"])
output = open("./"+"index.html","w",encoding= "utf-16")
output.write(indexHtml)