mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
TXTZ Output plugin: Only keep images if the text format is one that can reference images. Fixes #2039474 [Images should not be saved when converting to TXTZ](https://bugs.launchpad.net/calibre/+bug/2039474)
This commit is contained in:
parent
c86de09698
commit
79db6e1f75
@ -127,6 +127,9 @@ class TXTZOutput(TXTOutput):
|
||||
from calibre.ebooks.oeb.base import OEB_IMAGES, xml2str
|
||||
from calibre.utils.zipfile import ZipFile
|
||||
|
||||
can_reference_images = opts.txt_output_formatting.lower() in ('markdown', 'textile')
|
||||
can_reference_images = can_reference_images and opts.keep_image_references
|
||||
|
||||
with TemporaryDirectory('_txtz_output') as tdir:
|
||||
# TXT
|
||||
txt_name = 'index.txt'
|
||||
@ -153,11 +156,14 @@ class TXTZOutput(TXTOutput):
|
||||
else:
|
||||
path = os.path.join(tdir, os.path.dirname(item.href))
|
||||
href = os.path.basename(item.href)
|
||||
ipath = os.path.join(path, href)
|
||||
is_cover = item.href == cover_href
|
||||
if can_reference_images or is_cover:
|
||||
os.makedirs(path, exist_ok=True)
|
||||
with open(os.path.join(path, href), 'wb') as imgf:
|
||||
with open(ipath, 'wb') as imgf:
|
||||
imgf.write(item.data)
|
||||
if item.href == cover_href:
|
||||
cover_relhref = os.path.relpath(imgf.name, tdir).replace(os.sep, '/')
|
||||
if is_cover:
|
||||
cover_relhref = os.path.relpath(ipath, tdir).replace(os.sep, '/')
|
||||
|
||||
# Metadata
|
||||
with open(os.path.join(tdir, 'metadata.opf'), 'wb') as mdataf:
|
||||
|
Loading…
x
Reference in New Issue
Block a user