From 412c64e58b2a9907762ba6c2085749445261c146 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Jul 2009 22:13:33 -0600 Subject: [PATCH] Fix crash when converting span tags with size attribute not a pure number. Occurs in some MOBI books. --- src/calibre/ebooks/oeb/transforms/flatcss.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 9f5deb5404..98745ebbc3 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -199,19 +199,21 @@ class CSSFlattener(object): if node.tag == XHTML('font'): node.tag = XHTML('span') if 'size' in node.attrib: + def force_int(raw): + return int(re.search(r'([0-9+-]+)', raw).group(1)) size = node.attrib['size'].strip() if size: fnums = self.context.source.fnums if size[0] in ('+', '-'): # Oh, the warcrimes - esize = 3 + int(size) + esize = 3 + force_int(size) if esize < 1: esize = 1 if esize > 7: esize = 7 cssdict['font-size'] = fnums[esize] else: - cssdict['font-size'] = fnums[int(size)] + cssdict['font-size'] = fnums[force_int(size)] del node.attrib['size'] if 'color' in node.attrib: cssdict['color'] = node.attrib['color']