This commit is contained in:
Mark Pilgrim
2009-05-29 01:23:36 -07:00
parent c9a3917fec
commit c59e8d8165
4 changed files with 62 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/python3
# TODO:
# - fix internal xrefs (look for href=<in [chapters]>.html)
# - fix duplicate IDs
# - print stylesheet
chapters = []
for line in open('index.html'):
if not line.count('<li') or not line.count('<a href'):
continue
chapters.append(line.split('<a href=', 1)[1].split('>', 1)[0])
out = open('build/single.html', 'w', encoding="utf-8")
out.write(open('util/single-header.html', encoding="utf-8").read())
out.write("<style>\n")
for filename in chapters:
include = False
id = "chapter-" + filename.split(".", 1)[0]
for line in open(filename, encoding="utf-8"):
if line.count('</style>'):
include = False
if include and not line.count('counter-reset'):
line = "#{0} {1}".format(id, line)
line = line.replace(",", ", #{0} ".format(id))
out.write(line)
if line.count('<style>'):
include = True
out.write("</style>\n")
out.write(open('util/single-header2.html', encoding="utf-8").read())
for filename in chapters:
include = False
id = "chapter-" + filename.split(".", 1)[0]
out.write("<div id={0}>\n".format(id))
for line in open(filename, encoding="utf-8"):
if line.count('<h1>'):
include = True
if line.count('<p class=nav') or line.count('<p class=c>&copy;'):
include = False
if include:
out.write(line)
out.write("</div>\n")
out.write(open('util/single-footer.html', encoding="utf-8").read())
out.close()
+3
View File
@@ -0,0 +1,3 @@
<p class=c>&copy; 2001&ndash;9 <a href=about.html>Mark Pilgrim</a>
</body>
</html>
+10
View File
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Dive into Python 3</title>
<link rel=stylesheet href=dip3.css>
<style>
body{counter-reset:h1 -2}
h1:before{counter-increment:h1}
</style>
+3
View File
@@ -0,0 +1,3 @@
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
</head>
<body>