Skip to content

Commit

Permalink
Replace word boundaries with negative assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 authored and acabal committed Jul 25, 2024
1 parent 788caf1 commit 3089cac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3618,7 +3618,7 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N
nodes = dom.xpath("/html/body//dd[contains(@epub:type, 'glossdef')]")
source_text = " ".join([node.inner_text() for node in nodes])
for glossary_index, glossary_value in enumerate(glossary_usage):
if glossary_value[1] is False and regex.search(r"\b\L<val>\b", source_text, flags=regex.IGNORECASE, val=[glossary_value[0]]):
if glossary_value[1] is False and regex.search(r"(?<!\w)\L<val>(?!\w)", source_text, flags=regex.IGNORECASE, val=[glossary_value[0]]):
glossary_usage[glossary_index] = (glossary_value[0], True)

# Test against word boundaries to not match `halftitlepage`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<search-key-group href="text/glossary.xhtml#bar">
<match value="R+L=J"/>
</search-key-group>
<search-key-group href="text/glossary.xhtml#xyz">
<match value="M.O."/>
</search-key-group>
<search-key-group href="text/glossary.xhtml#abc">
<match value="’versal"/>
</search-key-group>
</search-key-map>
2 changes: 2 additions & 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 @@ -10,6 +10,8 @@
<h2 epub:type="ordinal z3998:roman">I</h2>
<p>He ate some food.</p>
<p>A common theory was R+L=J.</p>
<p>A ’versal truth.</p>
<p>An unknown M.O.</p>
</section>
</body>
</html>

0 comments on commit 3089cac

Please sign in to comment.