From 9a9530f34bd352e115ca9ad243a99b28b2b80c13 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 20 Oct 2013 10:40:42 -0400 Subject: [PATCH] Fix issue # 1242261: Htmlz does not apply inline css from . --- src/calibre/ebooks/htmlz/oeb2html.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index 06ba2b63d3..a0bbc4af18 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -11,6 +11,7 @@ Transform OEB content into a single (more or less) HTML file. ''' import os +import re from functools import partial from lxml import html @@ -254,10 +255,15 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): attribs = elem.attrib style_a = '%s' % style + style_a = style_a if style_a else '' if tag == 'body': + # Change the body to a div so we can merge multiple files. tag = 'div' - if not style['page-break-before'] == 'always': - style_a = 'page-break-before: always;' + ' ' if style_a else '' + style_a + # Add page-break-brefore: always because renders typically treat a new file (we're merging files) + # as a page break and remove all other page break types that might be set. + style_a = 'page-break-before: always; %s' % re.sub('page-break-[^:]+:[^;]+;?', '', style_a) + # Remove unnecessary spaces. + style_a = re.sub('\s{2,}', ' ', style_a).strip() tags.append(tag) # Remove attributes we won't want.