Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Option for images without caption to also remove caption number
  • Loading branch information
Klaus Thoden committed Jun 4, 2018
1 parent 7d735cc commit 4c960b8
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions imxml2epub.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*- # -*- 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 os
import sys import sys
Expand All @@ -22,6 +22,7 @@
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", dest="CONFIG_FILE", help="Name of configuration file", metavar="CONFIGURATION") 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("-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() args = parser.parse_args()


if args.CONFIG_FILE is not None: if args.CONFIG_FILE is not None:
Expand Down Expand Up @@ -510,7 +511,6 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber):


contentopf = addToContentopf(contentopf, content_opf_filename, content_opf_fileid, 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") idFigure = xmlFigure.find(".//anchor").get("id")
intFigureNumber = dictFigures[idFigure] intFigureNumber = dictFigures[idFigure]
if xmlFigure.tag == "EOAfigure": if xmlFigure.tag == "EOAfigure":
Expand All @@ -525,13 +525,18 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber):
xmlFigureImage.set("alt", "") xmlFigureImage.set("alt", "")
xmlFigureImage.set("style", "width: " + strImageWidth + "%") xmlFigureImage.set("style", "width: " + strImageWidth + "%")
xmlFigure.append(xmlFigureImage) xmlFigure.append(xmlFigureImage)
xmlFigureCaption.tag = "p"
strFigureCaption = xmlFigureCaption.text or "" if args.nocaption:
# FIX pass
xmlFigureCaption.text = lang_dict["fig"][strLanguage] + " " + str(intFigureNumber) + ": " + strFigureCaption else:
xmlFigure.addnext(xmlFigureCaption) xmlFigureCaption = xmlFigure.find(".//caption")
# Change the tag of the parent <p>-Tag to <div> so that it may be removed xmlFigureCaption.tag = "p"
#xmlFigure.getparent().tag = "div" strFigureCaption = xmlFigureCaption.text or ""
# FIX
xmlFigureCaption.text = lang_dict["fig"][strLanguage] + " " + str(intFigureNumber) + ": " + strFigureCaption
xmlFigure.addnext(xmlFigureCaption)
# Change the tag of the parent <p>-Tag to <div> so that it may be removed
#xmlFigure.getparent().tag = "div"


xml_figures_hyperimage = xmlEbookTree.xpath(".//EOAfigure[@type='hionly'] | .//EOAlsfigure[@type='hionly']") xml_figures_hyperimage = xmlEbookTree.xpath(".//EOAfigure[@type='hionly'] | .//EOAlsfigure[@type='hionly']")
logging.debug("found %s hyperimage figures" % len(xml_figures_hyperimage)) logging.debug("found %s hyperimage figures" % len(xml_figures_hyperimage))
Expand Down

0 comments on commit 4c960b8

Please sign in to comment.