From 6d5b2d6e8adbf9b6806f80f5b7e85b1bfc42b04f Mon Sep 17 00:00:00 2001 From: kthoden Date: Tue, 22 Jun 2021 19:39:34 +0200 Subject: [PATCH] Implement info box in EPUB --- src/data/epub_files/eoa-epub-core.css | 12 ++++++++++ src/imxml2epub.py | 32 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/data/epub_files/eoa-epub-core.css b/src/data/epub_files/eoa-epub-core.css index c507d5d..9652cc3 100644 --- a/src/data/epub_files/eoa-epub-core.css +++ b/src/data/epub_files/eoa-epub-core.css @@ -45,4 +45,16 @@ span.red { color: red; } +.box { + background-color: #eee; + padding-bottom: .1px; + padding-top: .1px +} + +.box * { + margin-left: 30px; + margin-right: 30px +} + + $FONTFACESPEC diff --git a/src/imxml2epub.py b/src/imxml2epub.py index 97da7e9..b71df10 100755 --- a/src/imxml2epub.py +++ b/src/imxml2epub.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2021-04-23 09:58:44 (kthoden)> +# Time-stamp: <2021-06-22 19:31:21 (kthoden)> """ Convert a customized DocBook XML file into a set of files that constitute the contents of an EPUB file. @@ -778,6 +778,31 @@ def add_css_snippet(css_snippet, css_file): logging.info("Found a divider.") xmlParagraph.text = "*" +logging.info(f"{logseparator}Preparing Info Boxes") +for xmlChapter in xmlChapters: + box_heads = xmlChapter.xpath(".//*[@style='boxhead']") + for box in box_heads: + box_constituents = list() + box.tag = "b" + del box.attrib["style"] + box_constituents.append(box) + div_element = etree.Element("boxdiv") + div_element.set("class", "box") + box.addprevious(div_element) + + following_elements = box.xpath("./following-sibling::*") + + for fol in following_elements: + folstyle = fol.get("style") + if folstyle == None or folstyle != "box": + break + else: + del fol.attrib["style"] + box_constituents.append(fol) + + for consti in box_constituents: + div_element.append(consti) + logging.info(f"{logseparator}Preparing Figures") xmlFigures = xmlEbookTree.xpath(".//EOAfigure[not(contains(@type,'hionly'))]") logging.info("Found %s figures", len(xmlFigures)) @@ -1424,7 +1449,6 @@ class FootnoteError(Exception): else: xml_verse.set("class", "verse") - logging.info(f"{logseparator}Preparing Equations") for xmlChapter in xmlChapters: xmlEquations = xmlChapter.findall(".//EOAequation") @@ -1939,6 +1963,10 @@ class FootnoteError(Exception): etree.strip_attributes(xmlEbookTree, "id-text", "noindent", "type", "label", "spacebefore", "rend", "hielement", "corresp") # also contained "id" etree.strip_elements(xmlEbookTree, "citekey", "originalcontents", "elementtoberemoved", with_tail=False) +infoboxes = xmlEbookTree.findall("//boxdiv") +for infobox in infoboxes: + infobox.tag = "div" + logging.info("Write every Part and Chapter into one file") xmlChapters = xmlEbookTree.findall("//div1") listParts = []