From 65ca22dfe7f9278a631ae4a063a2527a226514c3 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Wed, 28 Jan 2009 07:35:10 -0500 Subject: [PATCH] Fix fix to #1716 to produce more valid XHTML. --- src/calibre/ebooks/html.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 2e2a27e172..4a5cdbb514 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -562,14 +562,16 @@ class Processor(Parser): text = u' '.join([t.strip() for t in elem.xpath('descendant::text()')]) self.log_info('\tDetected chapter: %s', text[:50]) chapter_mark = self.opts.chapter_mark - if chapter_mark != 'none': - tag = 'hr' if chapter_mark != 'pagebreak' else 'br' - mark = etree.Element(tag) + if chapter_mark == 'pagebreak': + style = elem.get('style', '').split(';') + style = filter(None, map(lambda x: x.strip(), style)) + style.append('page-break-before: always') + elem.set('style', '; '.join(style)) + elif chapter_mark in ('rule', 'both'): + mark = etree.Element('hr') elem.addprevious(mark) if chapter_mark == 'both': mark.set('style', 'page-break-before: always') - elif chapter_mark == 'pagebreak': - mark.set('style', 'page-break-after: always') def save(self): style_path = os.path.splitext(os.path.basename(self.save_path()))[0]