diff --git a/util/flatten.py b/util/flatten.py new file mode 100644 index 0000000..b849900 --- /dev/null +++ b/util/flatten.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +# TODO: +# - fix internal xrefs (look for href=.html) +# - fix duplicate IDs +# - print stylesheet + +chapters = [] +for line in open('index.html'): + if not line.count('', 1)[0]) + +out = open('build/single.html', 'w', encoding="utf-8") +out.write(open('util/single-header.html', encoding="utf-8").read()) +out.write("'): + 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('\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("
\n".format(id)) + for line in open(filename, encoding="utf-8"): + if line.count('

'): + include = True + if line.count('

\n") + +out.write(open('util/single-footer.html', encoding="utf-8").read()) +out.close() diff --git a/util/single-footer.html b/util/single-footer.html new file mode 100644 index 0000000..5cfbd87 --- /dev/null +++ b/util/single-footer.html @@ -0,0 +1,3 @@ +

© 2001–9 Mark Pilgrim + + diff --git a/util/single-header.html b/util/single-header.html new file mode 100644 index 0000000..1464658 --- /dev/null +++ b/util/single-header.html @@ -0,0 +1,10 @@ + + + + +Dive into Python 3 + + diff --git a/util/single-header2.html b/util/single-header2.html new file mode 100644 index 0000000..e1eb178 --- /dev/null +++ b/util/single-header2.html @@ -0,0 +1,3 @@ + + +