KEPUB Output: Include leading whitespace in kobo sentence span tags. This prevents unsightly breaks when highlighting across formatted text on the Kobo. Fixes #2103926 [Highlighting space after italicized words on Kobo device](https://bugs.launchpad.net/calibre/+bug/2103926)

This commit is contained in:
Kovid Goyal 2025-03-24 11:39:51 +05:30
parent 32a27227a4
commit 28c1cb4711
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 12 deletions

View File

@ -180,14 +180,16 @@ def add_kobo_spans(inner, root_lang):
ws = None ws = None
if num := len(text) - len(stripped): if num := len(text) - len(stripped):
ws = text[:num] ws = text[:num]
before = None if stripped else ws
if at: if at:
parent[at-1].tail = ws parent[at-1].tail = before
else: else:
parent.text = ws parent.text = before
if stripped: 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 = kobo_span(parent)
s.text = stripped[pos:pos+sz] s.text = text[pos:pos+sz]
parent.insert(at, s) parent.insert(at, s)
at += 1 at += 1