-
Notifications
You must be signed in to change notification settings - Fork 14
/
pad_to_html.py
94 lines (83 loc) · 1.35 KB
/
pad_to_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
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
import sys
import bleach
from markdown2 import markdown
from urllib2 import urlopen
# built from here https://www.w3.org/TR/html-markup/elements.html
ALLOWED_TAGS = (
"a",
"abbr",
"b",
"blockquote",
"br",
"col",
"colgroup",
"dd",
"del",
"div",
"dl",
"dt",
"em",
"footer",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"i",
"img",
"label",
"legend",
"li",
"nav",
"ol",
"p",
"pre",
"q",
"s",
"section",
"small",
"span",
"strong",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"u",
"ul",
"wbr",
)
header = """
<!doctype html>
<html>
<head>
<title>Neutrinet Hub</title>
<link href="../css/pad.css" rel="stylesheet">
<body>
"""
footer = """
<footer>
<hr>
<p><a href="..">Go back to Neutrinet website</a></p>
</footer>
</body>
</html>
"""
def main():
source, destination = sys.argv[1:]
source = urlopen(source + "/export/txt").read()
source = "\n".join(filter(lambda x: not x.lstrip().startswith("//"), source.split("\n")))
html = bleach.clean(markdown(source), tags=ALLOWED_TAGS)
html = header + html + footer
open(destination, "w").write(html.encode("Utf-8"))
if __name__ == '__main__':
main()