Fix wrapping of multiple children

This commit is contained in:
Kovid Goyal 2024-10-20 12:49:53 +05:30
parent 1f87c3c87a
commit 50bdf1c8a8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -248,6 +248,9 @@ class Structure(BaseTest):
'<p>One</p> Two. Three <p>Four': '<p>One</p> Two. Three <p>Four':
'<body><p><span id="1">One</span></p><span id="2"> Two. </span><span id="3">Three </span><p><span id="4">Four</span></p>', '<body><p><span id="1">One</span></p><span id="2"> Two. </span><span id="3">Three </span><p><span id="4">Four</span></p>',
'<p>Here is some <b>bold, </b><i>italic, </i><u>underline, </u> text.':
'<body><p><span id="1">Here is some <b>bold, </b><i>italic, </i><u>underline, </u> text.</span></p>',
}.items()): }.items()):
root = parse(text, namespace_elements=True) root = parse(text, namespace_elements=True)
orig = normalize_markup(root) orig = normalize_markup(root)

View File

@ -171,10 +171,12 @@ def mark_sentences_in_html(root, lang: str = '', voice: str = '') -> list[Senten
w.append(c) w.append(c)
first_child = c first_child = c
if in_range: if in_range:
if last_child is not first_child:
w.append(last_child)
if c is last_child: if c is last_child:
if last_child is not first_child:
w.append(c)
break break
else:
w.append(c)
self.replace_reference_to_child(last_child, w) self.replace_reference_to_child(last_child, w)
return w return w