MOBI output:Improve conversion of tables and Fix #1654 (Tor ePub fails in any2mobi)

This commit is contained in:
Kovid Goyal 2009-01-19 19:48:41 -08:00
commit d766127c10
2 changed files with 13 additions and 4 deletions

View File

@ -140,7 +140,7 @@ class MobiMLizer(object):
para = bstate.para
if tag in SPECIAL_TAGS and not text:
para = para if para is not None else bstate.body
elif para is None:
elif para is None or tag in ('td', 'th'):
body = bstate.body
if bstate.pbreak:
etree.SubElement(body, MBP('pagebreak'))
@ -160,7 +160,8 @@ class MobiMLizer(object):
elif indent != 0 and abs(indent) < self.profile.fbase:
indent = (indent / abs(indent)) * self.profile.fbase
if tag in NESTABLE_TAGS:
para = wrapper = etree.SubElement(parent, XHTML(tag))
para = wrapper = etree.SubElement(
parent, XHTML(tag), attrib=istate.attrib)
bstate.nested.append(para)
if tag == 'li' and len(istates) > 1:
istates[-2].list_num += 1
@ -340,6 +341,10 @@ class MobiMLizer(object):
tag = 'tr'
elif display == 'table-cell':
tag = 'td'
if tag in TABLE_TAGS:
for attr in ('rowspan', 'colspan'):
if attr in elem.attrib:
istate.attrib[attr] = elem.attrib[attr]
text = None
if elem.text:
if istate.preserve:
@ -377,6 +382,6 @@ class MobiMLizer(object):
bstate.vpadding += bstate.vmargin
bstate.vmargin = 0
bstate.vpadding += vpadding
if tag in NESTABLE_TAGS and bstate.nested:
if bstate.nested and bstate.nested[-1].tag == elem.tag:
bstate.nested.pop()
istates.pop()

View File

@ -364,7 +364,11 @@ class MobiWriter(object):
if image.format not in ('JPEG', 'GIF'):
width, height = image.size
area = width * height
format = 'GIF' if area <= 40000 else 'JPEG'
if area <= 40000:
format = 'GIF'
else:
image = image.convert('RGBA')
format = 'JPEG'
changed = True
if dimen is not None:
image.thumbnail(dimen, Image.ANTIALIAS)