-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (42 loc) · 1.18 KB
/
main.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
import markdown
import os
import sys
def md2html(mdstr):
exts = ['markdown.extensions.extra', 'markdown.extensions.codehilite', 'markdown.extensions.tables',
'markdown.extensions.toc']
html = '''
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<link href="./static/github-markdown.css" rel="stylesheet">
<title>UPC ACMCLUB Printer</title>
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
</style>
</head>
<body class="markdown-body">
%s
</body>
</html>
'''
ret = markdown.markdown(mdstr, extensions=exts)
return html % ret
if __name__ == '__main__':
if len(sys.argv) < 3:
print('usage: main.py source_filename target_file')
sys.exit()
infile = open(sys.argv[1], 'r')
md = infile.read()
infile.close()
if os.path.exists(sys.argv[2]):
os.remove(sys.argv[2])
outfile = open(sys.argv[2], 'a')
outfile.write(md2html(md))
outfile.close()
print('convert %s to %s success!' % (sys.argv[1], sys.argv[2]))