From 6d155607fd1113ce4979f7e2b70a8cea920a9136 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Nov 2011 09:18:50 +0530 Subject: [PATCH] Fix #892525 (calibre produces ePubs with around block elements) --- src/calibre/ebooks/oeb/transforms/flatcss.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 664b07baa5..ba90a31632 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -11,9 +11,8 @@ import operator import math from collections import defaultdict from lxml import etree -from calibre.ebooks.oeb.base import XHTML, XHTML_NS -from calibre.ebooks.oeb.base import CSS_MIME, OEB_STYLES -from calibre.ebooks.oeb.base import namespace, barename +from calibre.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, + namespace, barename, XPath) from calibre.ebooks.oeb.stylizer import Stylizer COLLAPSE = re.compile(r'[ \t\r\n\v]+') @@ -232,7 +231,10 @@ class CSSFlattener(object): cssdict['text-align'] = val del node.attrib['align'] 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: def force_int(raw): return int(re.search(r'([0-9+-]+)', raw).group(1))