diff --git a/src/calibre/ebooks/oeb/polish/kepubify.py b/src/calibre/ebooks/oeb/polish/kepubify.py index aa1b811a42..185c596908 100644 --- a/src/calibre/ebooks/oeb/polish/kepubify.py +++ b/src/calibre/ebooks/oeb/polish/kepubify.py @@ -180,14 +180,16 @@ def add_kobo_spans(inner, root_lang): ws = None if num := len(text) - len(stripped): ws = text[:num] + before = None if stripped else ws if at: - parent[at-1].tail = ws + parent[at-1].tail = before else: - parent.text = ws + parent.text = before if stripped: - for pos, sz in sentence_positions(stripped, lang): + text = (ws + stripped) if ws else stripped + for pos, sz in sentence_positions(text, lang): s = kobo_span(parent) - s.text = stripped[pos:pos+sz] + s.text = text[pos:pos+sz] parent.insert(at, s) at += 1 diff --git a/src/calibre/ebooks/oeb/polish/tests/kepubify.py b/src/calibre/ebooks/oeb/polish/tests/kepubify.py index bca3e32d78..8e42d85f2e 100644 --- a/src/calibre/ebooks/oeb/polish/tests/kepubify.py +++ b/src/calibre/ebooks/oeb/polish/tests/kepubify.py @@ -68,8 +68,8 @@ div#book-inner {{ margin-top: 0; margin-bottom: 0; }} with tail': - '
Script: with tail
', + '
Script: with tail
', '
Svg: mouse no tail': '
Svg: mouse' - ' no tail
', + ' no tail
', # encoding quirks '

A\xa0nbsp; ':