diff --git a/src/imxml2epub.py b/src/imxml2epub.py
index 82a86e6..0e9b316 100755
--- a/src/imxml2epub.py
+++ b/src/imxml2epub.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
-# Time-stamp: <2019-12-18 10:13:44 (kthoden)>
+# Time-stamp: <2020-01-14 14:56:34 (kthoden)>
""" Convert a customized DocBook XML file into a set of files that
constitute the contents of an EPUB file.
@@ -31,6 +31,7 @@
SCRIPT_PATH = Path( __file__ )
SCRIPT_NAME = SCRIPT_PATH.stem
+
DEFAULT_INPUT_DIR = \
Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input')
@@ -97,6 +98,13 @@
help="Specify the directory with files of the font (the font itself, License)",
)
+parser.add_argument(
+ "-him", "--hyperimage",
+ help="Link hyperlink references to online version.",
+ action="store_true"
+ )
+
+
args = parser.parse_args()
config_file = args.CONFIG_FILE
@@ -179,6 +187,12 @@
dictPagelabels = data["pagelabeldict"]
+if args.hyperimage:
+ logging.info("Enabled Hyperimage support")
+else:
+ pass
+
+
def get_mimetype(filename_suffix):
"""Return mimetype of image"""
if filename_suffix.lower() == ".jpg":
@@ -526,6 +540,7 @@ def add_css_snippet(css_snippet, css_file):
publication_series = cfgPublication.get("Technical", "Serie")
publication_number = cfgPublication.get("Technical", "Number")
publication_license = cfgPublication.get("Technical", "License")
+publication_landingpage = cfgPublication.get("Technical", "LandingPage")
try:
publication_isbn = cfgPublication.get("Technical", "ISBN-epub")
except:
@@ -738,7 +753,9 @@ def add_css_snippet(css_snippet, css_file):
xmlParagraph.find("head").tag = "h5"
logging.info(f"{logseparator}Preparing Figures")
-xmlFigures = xmlEbookTree.xpath(".//EOAfigure[not(@type='hionly')] | .//EOAlsfigure[not(@type='hionly')]")
+xmlFigures = xmlEbookTree.xpath(".//EOAfigure[not(contains(@type,'hionly'))]")
+libeoaconvert.debug_xml_here(xmlEbookTree, "find_eoafigures", DEBUG_DIR)
+logging.info("Found %s figures", len(xmlFigures))
for xmlFigure in xmlFigures:
# Copy File of the Image
# If it's in a subfolder, name of folder and name of image will be merged
@@ -808,9 +825,10 @@ def add_css_snippet(css_snippet, css_file):
# Change the tag of the parent
-Tag to
so that it may be removed
#xmlFigure.getparent().tag = "div"
-xml_figures_hyperimage = xmlEbookTree.xpath(".//EOAfigure[@type='hionly'] | .//EOAlsfigure[@type='hionly']")
-logging.debug("found %s hyperimage figures" % len(xml_figures_hyperimage))
+xml_figures_hyperimage = xmlEbookTree.xpath(".//EOAfigure[contains(@type,'hionly')]")
+logging.info("Found %s hyperimage figures", len(xml_figures_hyperimage))
for fig in xml_figures_hyperimage:
+ fig.clear()
fig.tag = "EOAhifigure"
logging.info(f"{logseparator}Preparing not numbered Figures")
@@ -1659,10 +1677,9 @@ class FootnoteError(Exception):
logging.info(f"{logseparator}Preparing Cross-References")
for xmlChapter in xmlChapters:
- xmlReferences = xmlChapter.findall(".//EOAref")
+ xmlReferences = xmlChapter.xpath(".//EOAref[not(parent::EOAref)]")
for xmlReference in xmlReferences:
-
# the new stuff
# label_text = xmlReference.find("Label").text[1:]
# logging.debug("label text is %s" % label_text)
@@ -1678,47 +1695,77 @@ class FootnoteError(Exception):
# eoa_id = eoa_id_element.get("id")
# end of the new stuff
+ hitarget_id_list = xmlReference.xpath("./ref/@hitarget")
- logging.info("XXXXXXXX")
- strResult = "!!! Cross Reference !!!"
-
- xmlReferenceLabel = xmlReference.find("Label")
- xmlReferenceLabelText = xmlReferenceLabel.text
-
- xmlReferenceRef = xmlReference.find("ref")
- xmlReferenceRefTarget = xmlReferenceRef.get("target")
-
- if xmlReferenceLabelText in dictEquations:
- logging.info("Verweis auf Array gefunden:" + xmlReferenceLabelText)
- strResult = dictEquations[xmlReferenceLabelText]
- if xmlReferenceRefTarget in dictEquations:
- logging.info("Verweis auf Equation gefunden:" + xmlReferenceRefTarget)
- strResult = dictEquations[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictLists:
- logging.info("Verweis auf Liste gefunden")
- strResult = dictLists[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictChapters:
- logging.info("Verweis auf Kapitel gefunden")
- strResult = dictChapters[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictSections:
- logging.info("Verweis auf Section gefunden")
- strResult = dictSections[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictFigures:
- logging.info("Verweis auf Abbildung gefunden")
- strResult = dictFigures[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictFootnotes:
- logging.info("Verweis auf Fussnote gefunden")
- strResult = dictFootnotes[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictTheorems:
- logging.info("Verweis auf Theorem gefunden")
- strResult = dictTheorems[xmlReferenceRefTarget]
- if xmlReferenceRefTarget in dictTables:
- logging.info("Verweis auf Tabelle gefunden")
- strResult = dictTables[xmlReferenceRefTarget]
- tmpTail = xmlReference.tail or ""
- #tmpTail = tmpTail.strip()
+ if len(hitarget_id_list) == 1:
+ hitarget_id = hitarget_id_list[0]
+ else:
+ hitarget_id = None
+
+ reference_type = xmlReference.get("type")
+ if reference_type == "text":
+ tmpTail = xmlReference.tail or ""
+ strResult = xmlReference.text
+ elif reference_type == "collage":
+ tmpTail = xmlReference.tail or ""
+ logging.debug("Found reference to a Hyperimage collage.")
+ subreferences = xmlReference.xpath("./EOAref[@type='number']")
+ strResult = ""
+ for subref in subreferences:
+ subref_tail = subref.tail or ""
+ subref_target = subref.xpath("./ref/@target")[0]
+ target_string = dictFigures[subref_target]
+ strResult += f"{target_string}{subref_tail}"
+ elif reference_type == "number":
+ logging.info("XXXXXXXX")
+ strResult = "!!! Cross Reference !!!"
+
+ xmlReferenceLabel = xmlReference.find("Label")
+ xmlReferenceLabelText = xmlReferenceLabel.text
+
+ xmlReferenceRef = xmlReference.find("ref")
+ xmlReferenceRefTarget = xmlReferenceRef.get("target")
+
+ if xmlReferenceLabelText in dictEquations:
+ logging.info("Verweis auf Array gefunden:" + xmlReferenceLabelText)
+ strResult = dictEquations[xmlReferenceLabelText]
+ if xmlReferenceRefTarget in dictEquations:
+ logging.info("Verweis auf Equation gefunden:" + xmlReferenceRefTarget)
+ strResult = dictEquations[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictLists:
+ logging.info("Verweis auf Liste gefunden")
+ strResult = dictLists[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictChapters:
+ logging.info("Verweis auf Kapitel gefunden")
+ strResult = dictChapters[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictSections:
+ logging.info("Verweis auf Section gefunden")
+ strResult = dictSections[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictFigures:
+ logging.info("Verweis auf Abbildung gefunden")
+ strResult = dictFigures[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictFootnotes:
+ logging.info("Verweis auf Fussnote gefunden")
+ strResult = dictFootnotes[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictTheorems:
+ logging.info("Verweis auf Theorem gefunden")
+ strResult = dictTheorems[xmlReferenceRefTarget]
+ if xmlReferenceRefTarget in dictTables:
+ logging.info("Verweis auf Tabelle gefunden")
+ strResult = dictTables[xmlReferenceRefTarget]
+ tmpTail = xmlReference.tail or ""
+ #tmpTail = tmpTail.strip()
+ else:
+ logging.error("Found unknown reference type: %s. Exiting", reference_type)
+ sys.exit(0)
logging.info("XXXXXXXX")
xmlReference.clear()
+ if args.hyperimage and hitarget_id and reference_type in ["collage", "number"]:
+ hyperimage_link = f"{publication_landingpage[:-11]}/{intChapterNumber - 1}/index.html#{hitarget_id}"
+ xmlReference.tag = "a"
+ xmlReference.set("href", hyperimage_link)
+ else:
+ pass
xmlReference.text = strResult
xmlReference.tail = tmpTail
@@ -1760,8 +1807,8 @@ class FootnoteError(Exception):
xmlIndexentry.clear()
xmlIndexentry.tail = tmpTail
etree.strip_tags(xmlEbookTree, "EOAlabel", "EOAindex", "EOApageref", "EOAcitenumeric", "EOAtable", "EOAref", "note", "div", "div2", "div3", "div4", "div5", "citetext", "newpage", "EOAciteyear", "EOAtablelabel" , "hi", "pagebreak", "page", "pagestyle", "EOAcitation", "EOAciteauthoryear", "EOAcitemanual", "EOAprintbibliography", "EOAindexperson", "EOAprintindex", "EOAindexlocation", "EOAprintpersonindex", "EOAprintlocationindex","anchor", "temp", "EOAletterhead", "EOAhifigure", "EOAtocentry")
-etree.strip_attributes(xmlEbookTree, "id-text", "noindent", "type", "label", "spacebefore", "rend") # also contained "id"
-etree.strip_elements(xmlEbookTree, "citekey", with_tail=False)
+etree.strip_attributes(xmlEbookTree, "id-text", "noindent", "type", "label", "spacebefore", "rend", "hielement") # also contained "id"
+etree.strip_elements(xmlEbookTree, "citekey", "originalcontents", with_tail=False)
logging.info("Write every Part and Chapter into one file")
xmlChapters = xmlEbookTree.findall("//div1")