Improve Mobipocket conversion of basic tables

This commit is contained in:
Marshall T. Vandegrift 2009-01-19 22:33:58 -05:00
parent 48340fe6ef
commit c198458f65

View File

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