Permalink
Browse files

Option for images without caption to also remove caption number

  • Loading branch information...
kthoden committed Jun 4, 2018
1 parent 7d735cc commit 4c960b8f72cd3e406c5131ac6231db3de9152605
Showing with 14 additions and 9 deletions.
  1. +14 −9 imxml2epub.py
View
@@ -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 <p>-Tag to <div> 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 <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']")
logging.debug("found %s hyperimage figures" % len(xml_figures_hyperimage))

0 comments on commit 4c960b8

Please sign in to comment.