From b089973dadf2334612be0d5fb8611941034b91f3 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 15 Jul 2024 17:14:23 -0400 Subject: [PATCH] Vary m-070 searches based on whether has children --- se/se_epub_lint.py | 10 +++++++++- tests/lint/metadata/m-070/golden/m-070-out.txt | 1 + .../m-070/in/src/epub/glossary-search-key-map.xml | 6 ++++++ .../metadata/m-070/in/src/epub/text/chapter-1.xhtml | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/se/se_epub_lint.py b/se/se_epub_lint.py index 1b3a666c..61754699 100644 --- a/se/se_epub_lint.py +++ b/se/se_epub_lint.py @@ -3515,7 +3515,15 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N if filename.name == "glossary-search-key-map.xml": ebook_flags["has_glossary_search_key_map"] = True # Map the glossary to tuples of the values and whether they’re used (initially false) - glossary_usage = list(map(lambda node: (node.get_attr("value"), False), xml_dom.xpath(".//*[@value]"))) + # If a has no children, its @value must appear in the text + # Otherwise, each of its children's @value must appear + for match in xml_dom.xpath("/search-key-map/search-key-group/match[@value]"): + values = match.xpath("./value[@value]") + if not values: + glossary_usage.append((match.get_attr("value"), False)) + else: + for value in values: + glossary_usage.append((value.get_attr("value"), False)) if filename.suffix == ".xhtml": # Read file contents into a DOM for querying diff --git a/tests/lint/metadata/m-070/golden/m-070-out.txt b/tests/lint/metadata/m-070/golden/m-070-out.txt index 6034b8e7..22cec68c 100644 --- a/tests/lint/metadata/m-070/golden/m-070-out.txt +++ b/tests/lint/metadata/m-070/golden/m-070-out.txt @@ -1,2 +1,3 @@ m-070 [Error] glossary-search-key-map.xml Glossary entry not found in the text. foo + pariahsss diff --git a/tests/lint/metadata/m-070/in/src/epub/glossary-search-key-map.xml b/tests/lint/metadata/m-070/in/src/epub/glossary-search-key-map.xml index 266070a0..aa902fa7 100644 --- a/tests/lint/metadata/m-070/in/src/epub/glossary-search-key-map.xml +++ b/tests/lint/metadata/m-070/in/src/epub/glossary-search-key-map.xml @@ -15,4 +15,10 @@ + + + + + + diff --git a/tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml b/tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml index 8a99425f..ed4fc696 100644 --- a/tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml +++ b/tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml @@ -13,6 +13,7 @@

A ’versal truth.

An unknown M.O.

Unsiker1 is an unusual term.

+

Pariahs is plural, but should match.