From 29b6d07ce0ba0607d395426b3ee6160f4826e322 Mon Sep 17 00:00:00 2001 From: David Grigg Date: Thu, 28 Dec 2023 14:12:22 +1100 Subject: [PATCH 1/3] Moved location of reading of xml:lang for title to avoid it picking up that in subtitle --- se/se_epub_generate_toc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/se/se_epub_generate_toc.py b/se/se_epub_generate_toc.py index d0e6d2f6..d6e136fc 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"): @@ -637,7 +635,9 @@ def evaluate_descendants(node: EasyXmlElement, toc_item: TocItem, textf: str) -> toc_item.subtitle = extract_strings(child) else: toc_item.title = extract_strings(child) - if toc_item.title and toc_item.subtitle: # then we're done + # this is the only time we need to worry about the language of the title + if not toc_item.lang: + toc_item.lang = child.get_attr("xml:lang") return toc_item return toc_item From 2d0a921336ca4d5a038247ad2d58d050621ce2e6 Mon Sep 17 00:00:00 2001 From: David Grigg Date: Thu, 28 Dec 2023 14:13:11 +1100 Subject: [PATCH 2/3] Added comment to clarify return action in generate_toc --- se/se_epub_generate_toc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/se/se_epub_generate_toc.py b/se/se_epub_generate_toc.py index d6e136fc..16b3a439 100644 --- a/se/se_epub_generate_toc.py +++ b/se/se_epub_generate_toc.py @@ -638,6 +638,8 @@ def evaluate_descendants(node: EasyXmlElement, toc_item: TocItem, textf: str) -> # this is the only time we need to worry about the language of the title 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 From ab09a0d6aab70c608fea0fcdb1f11573fe4644d6 Mon Sep 17 00:00:00 2001 From: David Grigg Date: Thu, 28 Dec 2023 20:32:47 +1100 Subject: [PATCH 3/3] Added xml:lang check for subtitle if title an ordinal and/or roman numeral --- se/se_epub_generate_toc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/se/se_epub_generate_toc.py b/se/se_epub_generate_toc.py index 16b3a439..abd1badc 100644 --- a/se/se_epub_generate_toc.py +++ b/se/se_epub_generate_toc.py @@ -633,9 +633,10 @@ 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) - # this is the only time we need to worry about the language of the title if not toc_item.lang: toc_item.lang = child.get_attr("xml:lang")