mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Only wrap leading whitespace if parent has no children
This commit is contained in:
parent
4ff64c0b21
commit
644f6701c6
@ -164,18 +164,21 @@ def add_kobo_spans(inner, root_lang):
|
|||||||
paranum += 1
|
paranum += 1
|
||||||
segnum = 0
|
segnum = 0
|
||||||
increment_next_para = False
|
increment_next_para = False
|
||||||
stripped = leading_whitespace_pat.sub('', text) or text
|
|
||||||
ws = None
|
|
||||||
if num := len(text) - len(stripped):
|
|
||||||
ws = text[:num]
|
|
||||||
try:
|
try:
|
||||||
at = 0 if after_child is None else parent.index(after_child) + 1
|
at = 0 if after_child is None else parent.index(after_child) + 1
|
||||||
except ValueError: # wrapped child
|
except ValueError: # wrapped child
|
||||||
at = parent.index(after_child.getparent()) + 1
|
at = parent.index(after_child.getparent()) + 1
|
||||||
|
stripped = leading_whitespace_pat.sub('', text)
|
||||||
|
if not at and not stripped and not len(parent):
|
||||||
|
stripped = text
|
||||||
|
ws = None
|
||||||
|
if num := len(text) - len(stripped):
|
||||||
|
ws = text[:num]
|
||||||
if at:
|
if at:
|
||||||
parent[at-1].tail = ws
|
parent[at-1].tail = ws
|
||||||
else:
|
else:
|
||||||
parent.text = ws
|
parent.text = ws
|
||||||
|
if stripped:
|
||||||
for pos, sz in sentence_positions(stripped, lang):
|
for pos, sz in sentence_positions(stripped, lang):
|
||||||
s = kobo_span(parent)
|
s = kobo_span(parent)
|
||||||
s.text = stripped[pos:pos+sz]
|
s.text = stripped[pos:pos+sz]
|
||||||
|
@ -59,8 +59,9 @@ div#book-inner {{ margin-top: 0; margin-bottom: 0; }}</style><script type="text/
|
|||||||
suffix = '</div></div></body></html>'
|
suffix = '</div></div></body></html>'
|
||||||
for src, expected in {
|
for src, expected in {
|
||||||
# basics
|
# basics
|
||||||
'<p>one</p><p>\xa0</p>':
|
'<p>one</p> <p>\xa0</p><p>\xa0<i>a</i></p>':
|
||||||
'<p><span class="koboSpan" id="kobo.1.1">one</span></p><p><span class="koboSpan" id="kobo.2.1"> </span></p>',
|
'<p><span class="koboSpan" id="kobo.1.1">one</span></p> <p><span class="koboSpan" id="kobo.2.1"> </span></p>'
|
||||||
|
'<p> <i><span class="koboSpan" id="kobo.3.1">a</span></i></p>',
|
||||||
|
|
||||||
'<p>Simple sentences. In a single paragraph.'
|
'<p>Simple sentences. In a single paragraph.'
|
||||||
'<p>A sentence <i>with <b>nested</b>, tailed</i> formatting. Another.':
|
'<p>A sentence <i>with <b>nested</b>, tailed</i> formatting. Another.':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user