mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix sentences in tail of parent element not being added
This commit is contained in:
parent
50bdf1c8a8
commit
a7736ab44d
@ -254,7 +254,9 @@ class Structure(BaseTest):
|
||||
}.items()):
|
||||
root = parse(text, namespace_elements=True)
|
||||
orig = normalize_markup(root)
|
||||
mark_sentences_in_html(root)
|
||||
sentences = mark_sentences_in_html(root)
|
||||
ids = tuple(int(s.elem_id[len(id_prefix):]) for s in sentences)
|
||||
self.assertEqual(len(ids), ids[-1])
|
||||
marked = normalize_markup(root)
|
||||
self.assertEqual(expected, marked)
|
||||
unmark_sentences_in_html(root)
|
||||
@ -263,8 +265,6 @@ class Structure(BaseTest):
|
||||
self.assertEqual(tuple(s.lang for s in sentences), ('eng', 'fra'))
|
||||
|
||||
|
||||
|
||||
|
||||
def find_tests():
|
||||
import unittest
|
||||
return unittest.defaultTestLoader.loadTestsFromTestCase(Structure)
|
||||
|
@ -84,6 +84,7 @@ def mark_sentences_in_html(root, lang: str = '', voice: str = '') -> list[Senten
|
||||
self.tag_name = tag_name
|
||||
self.lang = child_lang or lang_for_elem(elem, parent_lang)
|
||||
self.parent_lang = parent_lang
|
||||
self.parent_voice = parent_voice
|
||||
q = elem.get('data-calibre-tts', '')
|
||||
self.voice = parent_voice
|
||||
if q.startswith('{'): # }
|
||||
@ -127,6 +128,7 @@ def mark_sentences_in_html(root, lang: str = '', voice: str = '') -> list[Senten
|
||||
before = self.elem.tail[:start]
|
||||
span = self.make_wrapper(text, p)
|
||||
spans.append(span)
|
||||
ans.append(Sentence(span.get('id'), text, self.parent_lang, self.parent_voice))
|
||||
after = self.elem.tail[end:]
|
||||
self.elem.tail = before
|
||||
if after and spans:
|
||||
|
Loading…
x
Reference in New Issue
Block a user