diff --git a/src/calibre/ebooks/oeb/polish/split.py b/src/calibre/ebooks/oeb/polish/split.py index 1ccf5d288b..0102e774ca 100644 --- a/src/calibre/ebooks/oeb/polish/split.py +++ b/src/calibre/ebooks/oeb/polish/split.py @@ -420,6 +420,9 @@ def merge_html(container, names, master, insert_page_breaks=False): first_child.set('id', unique_anchor(seen_anchors, 'top')) seen_anchors.add(first_child.get('id')) + if insert_page_breaks: + first_child.set('style', first_child.get('style', '') + '; page-break-before: always') + amap[''] = first_child.get('id') # Fix links that point to local changed anchors @@ -428,9 +431,6 @@ def merge_html(container, names, master, insert_page_breaks=False): if q in amap: a.set('href', '#' + amap[q]) - if insert_page_breaks: - master_body.append(master_body.makeelement(XHTML('div'), style='page-break-after:always')) - for child in children: if isinstance(child, string_or_bytes): add_text(master_body, child)