diff --git a/se/se_epub_generate_toc.py b/se/se_epub_generate_toc.py index d0e6d2f6..abd1badc 100644 --- a/se/se_epub_generate_toc.py +++ b/se/se_epub_generate_toc.py @@ -591,8 +591,6 @@ def evaluate_descendants(node: EasyXmlElement, toc_item: TocItem, textf: str) -> """ children = node.xpath("./p | ./h1 | ./h2 | ./h3 | ./h4 | ./h5 | ./h6") for child in children: # we expect these to be h1, h2, h3, h4 etc - if not toc_item.lang: - toc_item.lang = child.get_attr("xml:lang") epub_type = child.get_attr("epub:type") if child.get_attr("hidden"): @@ -635,9 +633,14 @@ def evaluate_descendants(node: EasyXmlElement, toc_item: TocItem, textf: str) -> if "title" in epub_type: # this allows for `fulltitle` to work here, too if toc_item.title or toc_item.roman or toc_item.title_is_ordinal: # if title already filled, must be a subtitle toc_item.subtitle = extract_strings(child) + if toc_item.roman or toc_item.title_is_ordinal: # in these cases, we want to check language on subtitle + toc_item.lang = child.get_attr("xml:lang") else: toc_item.title = extract_strings(child) - if toc_item.title and toc_item.subtitle: # then we're done + if not toc_item.lang: + toc_item.lang = child.get_attr("xml:lang") + + if toc_item.title and toc_item.subtitle: # then we're done, get out of loop by returning return toc_item return toc_item