diff --git a/imxml2epub.py b/imxml2epub.py index f6e197c..06f766b 100755 --- a/imxml2epub.py +++ b/imxml2epub.py @@ -483,7 +483,7 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): print("-----------------------------------------------------") print("Preparing Figures") -xmlFigures = xmlEbookTree.xpath(".//EOAfigure | .//EOAlsfigure") +xmlFigures = xmlEbookTree.xpath(".//EOAfigure[not(@type='hionly')] | .//EOAlsfigure[not(@type='hionly')]") 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 @@ -493,11 +493,23 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): # Remove / from path strImageFileDir = re.sub("/", "", strImageFileDir) strImageFileName = os.path.basename(strImageFileString) - strImageFileNamewoSuffix = os.path.splitext(strImageFileName)[0] + strImageFileNamewoSuffix, strImageFileName_Suffix = os.path.splitext(strImageFileName) shutil.copy(os.getcwd() + "/" + strImageFileString, os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName) + if strImageFileName_Suffix.lower() == ".jpg": + extension_and_mime = "jpg" + elif strImageFileName_Suffix.lower() in [".png", ".pdf"]: + extension_and_mime = "png" + else: + print("Found an unrecognized image suffix: %s" % strImageFileName_Suffix) + sys.exit() + strImageFilepath = libeoaconvert.sanitizeImage(os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName, GM_PATH, TL_PATH) # Add copied file to contentopf - contentopf = addToContentopf(contentopf, "images/" + strImageFileDir + strImageFileNamewoSuffix + ".jpg", strImageFileDir + strImageFileNamewoSuffix + "jpg", "jpg") + content_opf_filename = "images" + os.path.sep + "{}{}.{}".format(strImageFileDir, strImageFileNamewoSuffix, extension_and_mime) + content_opf_fileid = "{}{}{}".format(strImageFileDir, strImageFileNamewoSuffix, extension_and_mime) + + contentopf = addToContentopf(contentopf, content_opf_filename, content_opf_fileid, extension_and_mime) + xmlFigureCaption = xmlFigure.find(".//caption") idFigure = xmlFigure.find(".//anchor").get("id") intFigureNumber = dictFigures[idFigure] @@ -509,7 +521,7 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): xmlFigure.clear() xmlFigure.tag = "p" xmlFigureImage = etree.Element("img") - xmlFigureImage.set("src", "images/" + strImageFileDir + strImageFileNamewoSuffix + ".jpg") + xmlFigureImage.set("src", "images/" + strImageFileDir + strImageFileNamewoSuffix + "." + extension_and_mime) xmlFigureImage.set("alt", "") xmlFigureImage.set("style", "width: " + strImageWidth + "%") xmlFigure.append(xmlFigureImage) @@ -521,6 +533,11 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): # 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)) +for fig in xml_figures_hyperimage: + fig.tag = "EOAhifigure" + print("-----------------------------------------------------") print("Preparing not numbered Figures") xmlFigures = xmlEbookTree.findall(".//EOAfigurenonumber") @@ -536,7 +553,8 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): shutil.copy(os.getcwd() + "/" + strImageFileString, os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName) strImageFilepath = libeoaconvert.sanitizeImage(os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName, GM_PATH, TL_PATH) # Add copied file to contentopf - contentopf = addToContentopf(contentopf, "images/" + strImageFileDir + strImageFileNamewoSuffix + ".jpg", strImageFileDir + strImageFileNamewoSuffix + "jpg", "jpg") + contentopf = addToContentopf(contentopf, "images/" + strImageFileDir + strImageFileNamewoSuffix + ".jpg", strImageFileDir + strImageFileNamewoSuffix + "-nonumber-jpg", "jpg") + logging.debug("Added a nonumber figure") strImageWidth = xmlFigure.find(".//width").text strImageWidth = strImageWidth.rstrip("\n") xmlFigure.clear() @@ -626,17 +644,14 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): kids = list(footnote.getchildren()) prefix = "[%s]" % footnote_name - print("hier 0" + prefix) # we would like to prepend this footnote identifier to the footnote element if footnote.text is not None: - print("hier 1" + prefix) # if the element starts with some text anyway, prepend it there # footnote.text = "%s %s" % (prefix, footnote.text) - + pass else: # if, however, the element begins with a child, prepend the text at the beginning of the first child instead if len(kids): - print("hier 2" + prefix) first_child = kids[0] # child_text = prefix child_text = "" @@ -649,7 +664,6 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): child_text += child_suffix first_child.text = child_text else: - print("hier 3" + prefix) # a totally empty footnote is weird, but who am I to judge? footnote.text = prefix @@ -666,7 +680,6 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): # append any text the footnote used to have to the destination destkids = list(destination.getchildren()) if len(destkids): - print("hier 4") # if the destination has children, append after the last one's tail last_kid = destkids[-1] prefix = last_kid.tail @@ -676,7 +689,6 @@ def bring_footnote_down_epub(footnote, footnote_name, destination): prefix += " " last_kid.tail = prefix + footnote_text else: - print("hier 5") # if the destination has no children, append to its text prefix = destination.text if prefix is None: @@ -981,8 +993,8 @@ class FootnoteError(Exception): strInlineElementFileName = os.path.basename(strInlineElementFilePath) strInlineElementDirName = os.path.dirname(strInlineElementFilePath) - strNewImagePath = os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strInlineElementDirName + strInlineElementFileName + strNewImagePath = os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strInlineElementDirName + strInlineElementFileName # trouble when there are subdirectories in Image path! # some thing goes wrong here: Images/png_300dpi/A.png