Implement #1769 (Remove first image in file during Conversion)

This commit is contained in:
Kovid Goyal 2009-02-04 19:11:26 -08:00
parent 70630c5dbc
commit e06000a20b
2 changed files with 15 additions and 1 deletions

View File

@ -141,6 +141,10 @@ help on using this feature.
action='store_true', action='store_true',
help=_('Use the cover detected from the source file in preference ' help=_('Use the cover detected from the source file in preference '
'to the specified cover.')) '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, structure('dont_split_on_page_breaks', ['--dont-split-on-page-breaks'], default=False,
help=_('Turn off splitting at page breaks. Normally, input files ' help=_('Turn off splitting at page breaks. Normally, input files '
'are automatically split at every page break into ' 'are automatically split at every page break into '

View File

@ -206,6 +206,13 @@ class HTMLProcessor(Processor, Rationalizer):
# self.convert_image(img) # self.convert_image(img)
Processor.save(self) 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 = {}, {} resource_map, stylesheets = {}, {}
toc = TOC(base_path=tdir, type='root') toc = TOC(base_path=tdir, type='root')
stylesheet_map = {} stylesheet_map = {}
first_image_removed = False
for htmlfile in filelist: for htmlfile in filelist:
logging.getLogger('html2epub').debug('Processing %s...'%htmlfile) logging.getLogger('html2epub').debug('Processing %s...'%htmlfile)
hp = HTMLProcessor(htmlfile, opts, os.path.join(tdir, 'content'), hp = HTMLProcessor(htmlfile, opts, os.path.join(tdir, 'content'),
resource_map, filelist, stylesheets) 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.populate_toc(toc)
hp.save() hp.save()
stylesheet_map[os.path.basename(hp.save_path())] = \ stylesheet_map[os.path.basename(hp.save_path())] = \