diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py
index eee86754cd..ed4465c8be 100644
--- a/src/calibre/ebooks/mobi/mobiml.py
+++ b/src/calibre/ebooks/mobi/mobiml.py
@@ -79,6 +79,9 @@ class FormatState(object):
class MobiMLizer(object):
+ def __init__(self, ignore_tables=False):
+ self.ignore_tables = ignore_tables
+
def transform(self, oeb, context):
oeb.logger.info('Converting XHTML to Mobipocket markup...')
self.oeb = oeb
@@ -341,6 +344,8 @@ class MobiMLizer(object):
tag = 'tr'
elif display == 'table-cell':
tag = 'td'
+ if tag in TABLE_TAGS and self.ignore_tables:
+ tag = 'span' if tag == 'td' else 'div'
if tag in TABLE_TAGS:
for attr in ('rowspan', 'colspan'):
if attr in elem.attrib:
diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py
index f1810d2f28..3c5a39ebd2 100644
--- a/src/calibre/ebooks/mobi/writer.py
+++ b/src/calibre/ebooks/mobi/writer.py
@@ -524,6 +524,10 @@ def config(defaults=None):
help=_('Modify images to meet Palm device size limitations.'))
mobi('toc_title', ['--toc-title'], default=None,
help=_('Title for any generated in-line table of contents.'))
+ mobi('ignore_tables', ['--ignore-tables'], default=False,
+ help=_('Render HTML tables as blocks of text instead of actual '
+ 'tables. This is neccessary if the HTML contains very large '
+ 'or complex tables.'))
profiles = c.add_group('profiles', _('Device renderer profiles. '
'Affects conversion of font sizes, image rescaling and rasterization '
'of tables. Valid profiles are: %s.') % ', '.join(_profiles))
@@ -581,7 +585,7 @@ def oeb2mobi(opts, inpath):
rasterizer.transform(oeb, context)
trimmer = ManifestTrimmer()
trimmer.transform(oeb, context)
- mobimlizer = MobiMLizer()
+ mobimlizer = MobiMLizer(ignore_tables=opts.ignore_tables)
mobimlizer.transform(oeb, context)
writer = MobiWriter(compression=compression, imagemax=imagemax)
writer.dump(oeb, outpath)
diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py
index f61b88c4d4..282bb03a30 100644
--- a/src/calibre/ebooks/oeb/base.py
+++ b/src/calibre/ebooks/oeb/base.py
@@ -1039,9 +1039,19 @@ class OEBBook(object):
def _ensure_cover_image(self):
cover = None
- spine0 = self.spine[0]
- html = spine0.data
- if self.metadata.cover:
+ hcover = self.spine[0]
+ if 'cover' in self.guide:
+ href = self.guide['cover'].href
+ item = self.manifest.hrefs[href]
+ media_type = item.media_type
+ if media_type in OEB_RASTER_IMAGES:
+ cover = item
+ elif media_type in OEB_DOCS:
+ hcover = item
+ html = hcover.data
+ if cover is not None:
+ pass
+ elif self.metadata.cover:
id = str(self.metadata.cover[0])
cover = self.manifest.ids[id]
elif MS_COVER_TYPE in self.guide:
@@ -1049,16 +1059,16 @@ class OEBBook(object):
cover = self.manifest.hrefs[href]
elif xpath(html, '//h:img[position()=1]'):
img = xpath(html, '//h:img[position()=1]')[0]
- href = spine0.abshref(img.get('src'))
+ href = hcover.abshref(img.get('src'))
cover = self.manifest.hrefs[href]
elif xpath(html, '//h:object[position()=1]'):
object = xpath(html, '//h:object[position()=1]')[0]
- href = spine0.abshref(object.get('data'))
+ href = hcover.abshref(object.get('data'))
cover = self.manifest.hrefs[href]
elif xpath(html, '//svg:svg[position()=1]'):
svg = copy.deepcopy(xpath(html, '//svg:svg[position()=1]')[0])
- href = os.path.splitext(spine0.href)[0] + '.svg'
- id, href = self.manifest.generate(spine0.id, href)
+ href = os.path.splitext(hcover.href)[0] + '.svg'
+ id, href = self.manifest.generate(hcover.id, href)
cover = self.manifest.add(id, href, SVG_MIME, data=svg)
if cover and not self.metadata.cover:
self.metadata.add('cover', cover.id)
diff --git a/src/calibre/gui2/dialogs/epub.py b/src/calibre/gui2/dialogs/epub.py
index c9bd3e6c46..161534a103 100644
--- a/src/calibre/gui2/dialogs/epub.py
+++ b/src/calibre/gui2/dialogs/epub.py
@@ -61,6 +61,7 @@ class Config(ResizableDialog, Ui_Dialog):
self.opt_toc_title.setVisible(False)
self.toc_title_label.setVisible(False)
self.opt_rescale_images.setVisible(False)
+ self.opt_ignore_tables.setVisible(False)
def initialize(self):
self.__w = []
diff --git a/src/calibre/gui2/dialogs/epub.ui b/src/calibre/gui2/dialogs/epub.ui
index 27627cccf8..cfa136e85f 100644
--- a/src/calibre/gui2/dialogs/epub.ui
+++ b/src/calibre/gui2/dialogs/epub.ui
@@ -93,7 +93,7 @@
-
- 0
+ 1
@@ -105,6 +105,36 @@
Book Cover
+
-
+
+
-
+
+
+
+
+
+ :/images/book.svg
+
+
+ true
+
+
+ Qt::AlignCenter
+
+
+
+
+
+ -
+
+
+ Use cover from &source file
+
+
+ true
+
+
+
-
@@ -156,36 +186,6 @@
- -
-
-
- Use cover from &source file
-
-
- true
-
-
-
- -
-
-
-
-
-
-
-
-
- :/images/book.svg
-
-
- true
-
-
- Qt::AlignCenter
-
-
-
-
-
opt_prefer_metadata_cover
@@ -479,6 +479,13 @@
+ -
+
+
+ &Ignore tables
+
+
+
-
diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py
index 44dc5d0ecb..ec2e17d3fa 100644
--- a/src/calibre/utils/config.py
+++ b/src/calibre/utils/config.py
@@ -97,7 +97,7 @@ class OptionParser(_OptionParser):
def merge(self, parser):
'''
- Add options from parser to self. In case of conflicts, confilicting options from
+ Add options from parser to self. In case of conflicts, conflicting options from
parser are skipped.
'''
opts = list(parser.option_list)
@@ -224,6 +224,8 @@ class OptionSet(object):
def update(self, other):
for name in other.groups.keys():
self.groups[name] = other.groups[name]
+ if name not in self.group_list:
+ self.group_list.append(name)
for pref in other.preferences:
if pref in self.preferences:
self.preferences.remove(pref)