Fix crash when converting span tags with size attribute not a pure number. Occurs in some MOBI books.

This commit is contained in:
Kovid Goyal 2009-07-20 22:13:33 -06:00
parent 7533100384
commit 412c64e58b

View File

@ -199,19 +199,21 @@ class CSSFlattener(object):
if node.tag == XHTML('font'): if node.tag == XHTML('font'):
node.tag = XHTML('span') node.tag = XHTML('span')
if 'size' in node.attrib: if 'size' in node.attrib:
def force_int(raw):
return int(re.search(r'([0-9+-]+)', raw).group(1))
size = node.attrib['size'].strip() size = node.attrib['size'].strip()
if size: if size:
fnums = self.context.source.fnums fnums = self.context.source.fnums
if size[0] in ('+', '-'): if size[0] in ('+', '-'):
# Oh, the warcrimes # Oh, the warcrimes
esize = 3 + int(size) esize = 3 + force_int(size)
if esize < 1: if esize < 1:
esize = 1 esize = 1
if esize > 7: if esize > 7:
esize = 7 esize = 7
cssdict['font-size'] = fnums[esize] cssdict['font-size'] = fnums[esize]
else: else:
cssdict['font-size'] = fnums[int(size)] cssdict['font-size'] = fnums[force_int(size)]
del node.attrib['size'] del node.attrib['size']
if 'color' in node.attrib: if 'color' in node.attrib:
cssdict['color'] = node.attrib['color'] cssdict['color'] = node.attrib['color']