#!/usr/bin/python3 # TODO: # - fix internal xrefs (look for href=.html) # - fix duplicate IDs import re # get list of chapters chapters = [] for line in open('index.html'): if not line.count('', 1)[0]) # construct regexes used to fix internal xrefs chapter_href = re.compile("".format("|".join(chapters))) chapter_fragment_href = re.compile("".format("|".join(chapters))) same_chapter_fragment_href = re.compile("]") # munge and combine chapter-specific styles 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(chapter_id, line) line = line.replace(",", ", #{0} ".format(chapter_id)) out.write(line) if line.count('\n") out.write(open('util/single-header2.html', encoding="utf-8").read()) # munge and combine chapters for filename in chapters: include = False id_prefix = filename.split(".", 1)[0] chapter_id = "chapter-" + id_prefix out.write("\n") out.write(open('util/single-footer.html', encoding="utf-8").read()) out.close()