From 4c960b8f72cd3e406c5131ac6231db3de9152605 Mon Sep 17 00:00:00 2001 From: Klaus Thoden Date: Mon, 4 Jun 2018 15:15:26 +0200 Subject: [PATCH] Option for images without caption to also remove caption number --- imxml2epub.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/imxml2epub.py b/imxml2epub.py index 645e035..630cab1 100755 --- a/imxml2epub.py +++ b/imxml2epub.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2018-05-31 16:55:44 (kthoden)> +# Time-stamp: <2018-06-01 16:17:44 (kthoden)> import os import sys @@ -22,6 +22,7 @@ parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", dest="CONFIG_FILE", help="Name of configuration file", metavar="CONFIGURATION") parser.add_argument("-f", "--font", help="Font to be used, default is TeX Gyre Termes", default="termes") +parser.add_argument("-nc", "--nocaption", help="No captions for figures.", action="store_true") args = parser.parse_args() if args.CONFIG_FILE is not None: @@ -510,7 +511,6 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): 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] if xmlFigure.tag == "EOAfigure": @@ -525,13 +525,18 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber): xmlFigureImage.set("alt", "") xmlFigureImage.set("style", "width: " + strImageWidth + "%") xmlFigure.append(xmlFigureImage) - xmlFigureCaption.tag = "p" - strFigureCaption = xmlFigureCaption.text or "" - # FIX - xmlFigureCaption.text = lang_dict["fig"][strLanguage] + " " + str(intFigureNumber) + ": " + strFigureCaption - xmlFigure.addnext(xmlFigureCaption) - # Change the tag of the parent

-Tag to

so that it may be removed - #xmlFigure.getparent().tag = "div" + + if args.nocaption: + pass + else: + xmlFigureCaption = xmlFigure.find(".//caption") + xmlFigureCaption.tag = "p" + strFigureCaption = xmlFigureCaption.text or "" + # FIX + xmlFigureCaption.text = lang_dict["fig"][strLanguage] + " " + str(intFigureNumber) + ": " + strFigureCaption + xmlFigure.addnext(xmlFigureCaption) + # 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))