Fix #892525 (calibre produces ePubs with <span> around block elements)

This commit is contained in:
Kovid Goyal 2011-11-23 09:18:50 +05:30
parent a8fb3b2025
commit 6d155607fd

View File

@ -11,9 +11,8 @@ import operator
import math import math
from collections import defaultdict from collections import defaultdict
from lxml import etree from lxml import etree
from calibre.ebooks.oeb.base import XHTML, XHTML_NS from calibre.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES,
from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES namespace, barename, XPath)
from calibre.ebooks.oeb.base import namespace, barename
from calibre.ebooks.oeb.stylizer import Stylizer from calibre.ebooks.oeb.stylizer import Stylizer
COLLAPSE = re.compile(r'[ \t\r\n\v]+') COLLAPSE = re.compile(r'[ \t\r\n\v]+')
@ -232,7 +231,10 @@ class CSSFlattener(object):
cssdict['text-align'] = val cssdict['text-align'] = val
del node.attrib['align'] del node.attrib['align']
if node.tag == XHTML('font'): if node.tag == XHTML('font'):
node.tag = XHTML('span') tags = ['descendant::h:%s'%x for x in ('p', 'div', 'table', 'h1',
'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'dl', 'blockquote')]
tag = 'div' if XPath('|'.join(tags))(node) else 'span'
node.tag = XHTML(tag)
if 'size' in node.attrib: if 'size' in node.attrib:
def force_int(raw): def force_int(raw):
return int(re.search(r'([0-9+-]+)', raw).group(1)) return int(re.search(r'([0-9+-]+)', raw).group(1))