Skip to content

Commit

Permalink
Implement info box in EPUB
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Jun 22, 2021
1 parent d094a22 commit 6d5b2d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/data/epub_files/eoa-epub-core.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 30 additions & 2 deletions src/imxml2epub.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 6d5b2d6

Please sign in to comment.