mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #1769 (Remove first image in file during Conversion)
This commit is contained in:
parent
70630c5dbc
commit
e06000a20b
@ -141,6 +141,10 @@ help on using this feature.
|
||||
action='store_true',
|
||||
help=_('Use the cover detected from the source file in preference '
|
||||
'to the specified cover.'))
|
||||
structure('remove_first_image', ['--remove-first-image'], default=False,
|
||||
help=_('Remove the first image from the input ebook. Useful if '
|
||||
'the first image in the source file is a cover and you '
|
||||
'are specifying an external cover.'))
|
||||
structure('dont_split_on_page_breaks', ['--dont-split-on-page-breaks'], default=False,
|
||||
help=_('Turn off splitting at page breaks. Normally, input files '
|
||||
'are automatically split at every page break into '
|
||||
|
@ -206,6 +206,13 @@ class HTMLProcessor(Processor, Rationalizer):
|
||||
# self.convert_image(img)
|
||||
Processor.save(self)
|
||||
|
||||
def remove_first_image(self):
|
||||
images = self.root.xpath('//img')
|
||||
if images:
|
||||
images[0].getparent().remove(images[0])
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
@ -227,10 +234,13 @@ def parse_content(filelist, opts, tdir):
|
||||
resource_map, stylesheets = {}, {}
|
||||
toc = TOC(base_path=tdir, type='root')
|
||||
stylesheet_map = {}
|
||||
first_image_removed = False
|
||||
for htmlfile in filelist:
|
||||
logging.getLogger('html2epub').debug('Processing %s...'%htmlfile)
|
||||
hp = HTMLProcessor(htmlfile, opts, os.path.join(tdir, 'content'),
|
||||
resource_map, filelist, stylesheets)
|
||||
if not first_image_removed and opts.remove_first_image:
|
||||
first_image_removed = hp.remove_first_image()
|
||||
hp.populate_toc(toc)
|
||||
hp.save()
|
||||
stylesheet_map[os.path.basename(hp.save_path())] = \
|
||||
|
Loading…
x
Reference in New Issue
Block a user