mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Splitting: Handle the tail of the split point correctly
EPUB/AZW3 Output: Fix splitting on page-break-after with plain text immediately following the split point causing the text to be added before rather than after the split point.
This commit is contained in:
parent
584beceee3
commit
26e23ac7a6
@ -339,6 +339,8 @@ class FlowSplitter(object):
|
|||||||
# We want to keep the descendants of the split point in
|
# We want to keep the descendants of the split point in
|
||||||
# Tree 1
|
# Tree 1
|
||||||
keep_descendants = True
|
keep_descendants = True
|
||||||
|
# We want the split point element, but not its tail
|
||||||
|
elem.tail = '\n'
|
||||||
|
|
||||||
continue
|
continue
|
||||||
if hit_split_point:
|
if hit_split_point:
|
||||||
@ -357,6 +359,18 @@ class FlowSplitter(object):
|
|||||||
for elem in tuple(body2.iterdescendants()):
|
for elem in tuple(body2.iterdescendants()):
|
||||||
if elem is split_point2:
|
if elem is split_point2:
|
||||||
if not before:
|
if not before:
|
||||||
|
# Keep the split point element's tail, if it contains non-whitespace
|
||||||
|
# text
|
||||||
|
tail = elem.tail
|
||||||
|
if tail and not tail.isspace():
|
||||||
|
parent = elem.getparent()
|
||||||
|
idx = parent.index(elem)
|
||||||
|
if idx == 0:
|
||||||
|
parent.text = (parent.text or '') + tail
|
||||||
|
else:
|
||||||
|
sib = parent[idx-1]
|
||||||
|
sib.tail = (sib.tail or '') + tail
|
||||||
|
# Remove the element itself
|
||||||
nix_element(elem)
|
nix_element(elem)
|
||||||
break
|
break
|
||||||
if elem in ancestors:
|
if elem in ancestors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user