Skip to content

Commit

Permalink
Vary m-070 searches based on whether <match> has children
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Jul 15, 2024
1 parent 9545297 commit b089973
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <match> has no <value> children, its @value must appear in the text
# Otherwise, each of its <value> 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
Expand Down
1 change: 1 addition & 0 deletions tests/lint/metadata/m-070/golden/m-070-out.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
m-070 [Error] glossary-search-key-map.xml Glossary entry not found in the text.
foo
pariahsss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
<search-key-group href="text/glossary.xhtml#def">
<match value="unsiker"/>
</search-key-group>
<search-key-group href="text/glossary.xhtml#ghi">
<match value="pariah">
<value value="pariahs"/>
<value value="pariahsss"/>
</match>
</search-key-group>
</search-key-map>
1 change: 1 addition & 0 deletions tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<p>A ’versal truth.</p>
<p>An unknown M.O.</p>
<p>Unsiker<a href="endnotes.xhtml#note-1" epub:type="noteref">1</a> is an unusual term.</p>
<p>Pariahs is plural, but should match.</p>
</section>
</body>
</html>

0 comments on commit b089973

Please sign in to comment.