"""A small EPUB for the e2e tests: 12 chapters of numbered paragraphs (long enough to scroll and to have a reading position), one footnote. Written to the path in argv[1]; e2e/global-setup.js calls it for every run.""" import sys import zipfile CONTAINER = """ """ def chapter(n): paras = [] for p in range(1, 41): text = f'Kapitel {n}, Absatz {p}. ' + ' '.join( f'Wort{w} im Absatz {p} des Kapitels {n} steht hier, damit der Absatz einige Zeilen lang wird.' for w in range(1, 6)) if n == 1 and p == 3: text += ' Mit Fußnote1.' paras.append(f'

{text}

') notes = '' if n == 12: notes = '' return f""" Kapitel {n}

Kapitel {n}

{''.join(paras)}{notes}""" def main(path, title='E2E Testbuch'): chapters = range(1, 13) manifest = ''.join(f'' for n in chapters) spine = ''.join(f'' for n in chapters) nav_items = ''.join(f'
  • Kapitel {n}
  • ' for n in chapters) opf = f""" diora-e2e-book {title}diorade {manifest} {spine} """ nav = f""" Inhalt""" with zipfile.ZipFile(path, 'w') as z: z.writestr(zipfile.ZipInfo('mimetype'), 'application/epub+zip', compress_type=zipfile.ZIP_STORED) z.writestr('META-INF/container.xml', CONTAINER, compress_type=zipfile.ZIP_DEFLATED) z.writestr('OEBPS/content.opf', opf, compress_type=zipfile.ZIP_DEFLATED) z.writestr('OEBPS/nav.xhtml', nav, compress_type=zipfile.ZIP_DEFLATED) for n in chapters: z.writestr(f'OEBPS/ch{n}.xhtml', chapter(n), compress_type=zipfile.ZIP_DEFLATED) if __name__ == '__main__': main(sys.argv[1], *sys.argv[2:3])