-
Notifications
You must be signed in to change notification settings - Fork 1
/
MakeHTML.py
67 lines (53 loc) · 1.62 KB
/
MakeHTML.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
import io
import re
def main():
with io.open('queneau_novel.txt','r',encoding='utf-8') as f:
lines = f.readlines()
print '<html>'
print '<link rel="stylesheet" href="slate.css" media="screen">'
print '<body>'
make_title()
make_toc(lines)
make_body(lines)
print '</body>'
print '</html>'
def make_title():
print '<center>'
print '<h1>Riverrun</h1>'
print '<p class="lead">An automatically generated NaNoGenMo 2016 submission. Based on James Joyce\'s <u>Ulysses</u></p>'
print '</center>'
print '<p> </p>'
print '<p> </p>'
def make_toc(lines):
print '<center>'
print '<h3>Table of Contents</h3>'
print '<p> </p>'
chapter = 1
for line in lines:
m=re.search('\[ ([0-9][0-9].*) \].*',line)
if m is not None:
print '<p><a href="#' + str(chapter) + '">' + m.groups(0)[0] + '</a></p>'
chapter += 1
print '</center>'
print '<p> </p>'
print '<p> </p>'
print '<p> </p>'
def make_body(lines):
for line in lines:
chapter = 1
if( re.search('\[.*\].*',line) ):
print '<a name="' + str(chapter) + '"></a>'
print "<h2>"
print line
print "</h2>"
chapter += 1
elif( re.search(' ',line) ):
print "<blockquote><i>"
print line.encode('ascii', 'xmlcharrefreplace')
print "</i></blockquote>"
else:
print "<p>"
print line.encode('ascii', 'xmlcharrefreplace')
print "</p>"
if __name__=="__main__":
main()