From 94729c90c53870ceb0c53ff8a528966906cc59e3 Mon Sep 17 00:00:00 2001 From: kthoden Date: Mon, 15 Jul 2019 14:54:45 +0200 Subject: [PATCH] Whitespace and encoding declaration for epub files --- imxml2epub.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/imxml2epub.py b/imxml2epub.py index fd4fc8d..4de5160 100755 --- a/imxml2epub.py +++ b/imxml2epub.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2019-07-12 14:29:26 (kthoden)> +# Time-stamp: <2019-07-15 15:10:49 (kthoden)> """ Convert a customized DocBook XML file into a set of files that constitute the contents of an EPUB file. @@ -417,8 +417,8 @@ def create_extra_font_css(css_selector, extrafontfiles): }} @font-face {{ - font-family: "{font_label}"; - src: url("fonts/{fontfile}"); + font-family: "{font_label}"; + src: url("fonts/{fontfile}"); }} """ @@ -1838,29 +1838,21 @@ class FootnoteError(Exception): # Content_OPF hinzufügen intTechnicalChapterNumber += 1 -tmpFileName = OUTPUT_DIR / "OEBPS/toc.ncx" +tocncx_filename = OUTPUT_DIR / "OEBPS/toc.ncx" logging.info("Saving toc.ncx") -tmpFile = open (tmpFileName, "w") -tmpResult = etree.tostring(tocncx, pretty_print=True, encoding="unicode") -tmpFile.write(tmpResult) -tmpFile.close() +tocncx.write( str(tocncx_filename), pretty_print=True, xml_declaration=True, encoding="utf-8") +contentopf_filename = OUTPUT_DIR / "OEBPS/content.opf" logging.info("Saving content.opf") -tmpFileName = OUTPUT_DIR / "OEBPS/content.opf" -tmpFile = open (tmpFileName, "w") -tmpResult = etree.tostring(contentopf, pretty_print=True, encoding="unicode") -tmpFile.write(tmpResult) -tmpFile.close() +contentopf.write( str(contentopf_filename), pretty_print=True, xml_declaration=True, encoding="utf-8") ############################################################################ # Finishing various Stuff # ############################################################################ -logging.info("Write Temporary XML-Tree") -ergebnisdatei = open(TEMP_DIR / "Devel_ebook.xml", "w") -ergebnis = etree.tostring(xmlEbookTree, pretty_print=True, encoding="unicode") -ergebnisdatei.write(ergebnis) -ergebnisdatei.close() +devel_ebook_file = TEMP_DIR / "Devel_ebook.xml" +logging.info(f"Write Temporary XML-Tree to {devel_ebook_file}.") +xmlEbookTree.write( str(devel_ebook_file), pretty_print=True, xml_declaration=True, encoding="utf-8") if args.no_epub: pass