mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Fix crash when converting span tags with size attribute not a pure number. Occurs in some MOBI books.
This commit is contained in:
parent
7533100384
commit
412c64e58b
@ -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']
|
||||
|
Loading…
x
Reference in New Issue
Block a user