mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 15:00:18 +00:00
tools
This commit is contained in:
@@ -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>©'):
|
||||
include = False
|
||||
if include:
|
||||
out.write(line)
|
||||
out.write("</div>\n")
|
||||
|
||||
out.write(open('util/single-footer.html', encoding="utf-8").read())
|
||||
out.close()
|
||||
@@ -0,0 +1,3 @@
|
||||
<p class=c>© 2001–9 <a href=about.html>Mark Pilgrim</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,3 @@
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
</head>
|
||||
<body>
|
||||
Reference in New Issue
Block a user