From d9635111d221d3ebe616b6d398de9a0a434ba1f8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 8 Jun 2013 09:08:11 +0530 Subject: [PATCH] Keep ancestors in second tree when splitting EPUB/AZW3 Output: When splitting HTML on page breaks, preserve tag structure in the split files. This fixes splitting losing some styling information for HTML files that define page breaks on deeply nested tags. Fixes #1188768 [fonts change midfile without being ordered to](https://bugs.launchpad.net/calibre/+bug/1188768) --- src/calibre/ebooks/oeb/transforms/split.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/transforms/split.py b/src/calibre/ebooks/oeb/transforms/split.py index 9e4c2a70e6..605a58a31f 100644 --- a/src/calibre/ebooks/oeb/transforms/split.py +++ b/src/calibre/ebooks/oeb/transforms/split.py @@ -353,12 +353,19 @@ class FlowSplitter(object): nix_element(elem) # Tree 2 + ancestors = frozenset(XPath('ancestor::*')(split_point2)) for elem in tuple(body2.iterdescendants()): if elem is split_point2: if not before: nix_element(elem) break - nix_element(elem, top=False) + if elem in ancestors: + # We have to preserve the ancestors as they could have CSS + # styles that are inherited/applicable, like font or + # width. So we only remove the text, if any. + elem.text = '\n' + else: + nix_element(elem, top=False) body2.text = '\n'