mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
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:
parent
32a27227a4
commit
28c1cb4711
@ -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
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ div#book-inner {{ margin-top: 0; margin-bottom: 0; }}</style><script type="text/
|
|||||||
|
|
||||||
'<p><span class="koboSpan" id="kobo.1.1">Simple sentences. </span><span class="koboSpan" id="kobo.1.2">In a single paragraph.</span></p>'
|
'<p><span class="koboSpan" id="kobo.1.1">Simple sentences. </span><span class="koboSpan" id="kobo.1.2">In a single paragraph.</span></p>'
|
||||||
'<p><span class="koboSpan" id="kobo.2.1">A sentence </span><i><span class="koboSpan" id="kobo.2.2">with </span>'
|
'<p><span class="koboSpan" id="kobo.2.1">A sentence </span><i><span class="koboSpan" id="kobo.2.2">with </span>'
|
||||||
'<b><span class="koboSpan" id="kobo.2.3">nested</span></b><span class="koboSpan" id="kobo.2.4">, tailed</span></i> '
|
'<b><span class="koboSpan" id="kobo.2.3">nested</span></b><span class="koboSpan" id="kobo.2.4">, tailed</span></i>'
|
||||||
'<span class="koboSpan" id="kobo.2.5">formatting. </span>'
|
'<span class="koboSpan" id="kobo.2.5"> formatting. </span>'
|
||||||
'<span class="koboSpan" id="kobo.2.6">Another.</span></p>',
|
'<span class="koboSpan" id="kobo.2.6">Another.</span></p>',
|
||||||
|
|
||||||
# img tags
|
# img tags
|
||||||
@ -86,17 +86,17 @@ div#book-inner {{ margin-top: 0; margin-bottom: 0; }}</style><script type="text/
|
|||||||
|
|
||||||
# nested block tags
|
# nested block tags
|
||||||
'<div>A div<div> nested.<ul><li>A list<p> with nested block</p> tail1</li> tail2</ul> tail3':
|
'<div>A div<div> nested.<ul><li>A list<p> with nested block</p> tail1</li> tail2</ul> tail3':
|
||||||
'<div><span class="koboSpan" id="kobo.1.1">A div</span><div> <span class="koboSpan" id="kobo.1.2">nested.</span>'
|
'<div><span class="koboSpan" id="kobo.1.1">A div</span><div><span class="koboSpan" id="kobo.1.2"> nested.</span>'
|
||||||
'<ul><li><span class="koboSpan" id="kobo.2.1">A list</span><p> <span class="koboSpan" id="kobo.3.1">with nested block</span></p>'
|
'<ul><li><span class="koboSpan" id="kobo.2.1">A list</span><p><span class="koboSpan" id="kobo.3.1"> with nested block</span></p>'
|
||||||
' <span class="koboSpan" id="kobo.3.2">tail1</span></li> <span class="koboSpan" id="kobo.3.3">tail2</span></ul>'
|
'<span class="koboSpan" id="kobo.3.2"> tail1</span></li><span class="koboSpan" id="kobo.3.3"> tail2</span></ul>'
|
||||||
' <span class="koboSpan" id="kobo.3.4">tail3</span></div></div>',
|
'<span class="koboSpan" id="kobo.3.4"> tail3</span></div></div>',
|
||||||
|
|
||||||
# skipped tags
|
# skipped tags
|
||||||
'<div>Script: <script>a = 1</script> with tail':
|
'<div>Script: <script>a = 1</script> with tail':
|
||||||
'<div><span class="koboSpan" id="kobo.1.1">Script: </span><script>a = 1</script> <span class="koboSpan" id="kobo.1.2">with tail</span></div>',
|
'<div><span class="koboSpan" id="kobo.1.1">Script: </span><script>a = 1</script><span class="koboSpan" id="kobo.1.2"> with tail</span></div>',
|
||||||
'<div>Svg: <svg>mouse</svg><i> no tail':
|
'<div>Svg: <svg>mouse</svg><i> no tail':
|
||||||
'<div><span class="koboSpan" id="kobo.1.1">Svg: </span><svg xmlns="http://www.w3.org/2000/svg">mouse</svg>'
|
'<div><span class="koboSpan" id="kobo.1.1">Svg: </span><svg xmlns="http://www.w3.org/2000/svg">mouse</svg>'
|
||||||
'<i> <span class="koboSpan" id="kobo.1.2">no tail</span></i></div>',
|
'<i><span class="koboSpan" id="kobo.1.2"> no tail</span></i></div>',
|
||||||
|
|
||||||
# encoding quirks
|
# encoding quirks
|
||||||
'<p>A\xa0nbsp; ':
|
'<p>A\xa0nbsp; ':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user