Skip to content

Commit

Permalink
Remove few xpath redundancies in y-003, add drama exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Vince authored and acabal committed Mar 8, 2024
1 parent 549aa4d commit 5199357
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@ def _lint_xhtml_typo_checks(filename: Path, dom: se.easy_xml.EasyXmlTree, file_c
messages.append(LintMessage("y-002", "Possible typo: punctuation followed directly by a letter, without a space.", se.MESSAGE_TYPE_WARNING, filename, typos))

# Check for paragraphs ending in lowercase letters, excluding a number of instances where that might be valid.
typos = [node.to_string() for node in dom.xpath("//p[re:test(., '[a-z]$') and not(@epub:type) and not(following-sibling::*[1]/node()[1][contains(@epub:type, 'z3998:roman')] or following-sibling::*[1][re:test(., '^([0-9]|first|second|third|fourth|fifth|sixth|seventh|eight|ninth|tenth)', 'i')]) and not(@class or contains(@epub:type, 'z3998:salutation')) and not(following-sibling::*[1][name() = 'blockquote' or name() = 'figure' or name() = 'table' or name() = 'footer' or name() = 'ul' or name() = 'ol'] or ancestor::*[name() = 'blockquote' or name() = 'footer' or name() = 'header' or name() = 'table' or name() = 'ul' or name() = 'ol' or name() = 'li' or name() = 'figure' or name() = 'hgroup' or re:test(@epub:type, '(z3998:drama|z3998:letter|dedication|halftitlepage)')])]")]
typos = [node.to_string() for node in dom.xpath("//p[re:test(., '[a-z]$') and not(@epub:type or @class) and not(following-sibling::*[1]/node()[1][contains(@epub:type, 'z3998:roman')] or following-sibling::*[1][re:test(., '^([0-9]|first|second|third|fourth|fifth|sixth|seventh|eight|ninth|tenth)', 'i')]) and not(following-sibling::*[1][name() = 'blockquote' or name() = 'figure' or name() = 'table' or name() = 'footer' or name() = 'ul' or name() = 'ol'] or ancestor::*[name() = 'blockquote' or name() = 'footer' or name() = 'header' or name() = 'table' or name() = 'li' or name() = 'figure' or name() = 'hgroup' or re:test(@epub:type, '(z3998:drama|dedication|halftitlepage)')])]")]
if typos:
messages.append(LintMessage("y-003", "Possible typo: paragraph missing ending punctuation.", se.MESSAGE_TYPE_WARNING, filename, typos))

Expand Down
18 changes: 18 additions & 0 deletions tests/lint/typos/y-003/in/src/epub/text/chapter-2.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" epub:prefix="z3998: http://www.daisy.org/z3998/2012/vocab/structure/, se: https://standardebooks.org/vocab/1.0" xml:lang="en-GB">
<head>
<title>II</title>
<link href="../css/core.css" rel="stylesheet" type="text/css"/>
<link href="../css/local.css" rel="stylesheet" type="text/css"/>
</head>
<body epub:type="bodymatter z3998:fiction">
<section id="chapter-2" epub:type="chapter">
<h2 epub:type="ordinal z3998:roman">II</h2>
<p>Recent controversy aside, the pauls could be said to resemble ungummed populations. If this was somewhat unclear, the temperatures could be said to resemble purer dads. A lidded rat's wound comes with it the thought that the cyclone fear is a wine.</p>
<section id="chapter-2-scene-1" epub:type="z3998:drama z3998:scene">
<!-- EXCLUSION 24, ancestor is z3998:drama -->
<p>Scene: Somewhere cold</p>
</section>
</section>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/lint/typos/y-003/in/src/epub/text/dedication.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body epub:type="frontmatter z3998:non-fiction">
<section id="dedication" epub:type="dedication">
<!-- EXCLUSION 24, epub:type dedication -->
<!-- EXCLUSION 25, epub:type dedication -->
<p>A dedication does not have to have ending punctuation</p>
</section>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body epub:type="frontmatter">
<section id="halftitlepage" epub:type="halftitlepage">
<h2 epub:type="fulltitle">Unknown Novel</h2>
<!-- EXCLUSION 25, ancestor halftitlepage -->
<!-- EXCLUSION 26, ancestor halftitlepage -->
<p>This will not cause an error</p>
</section>
</body>
Expand Down

0 comments on commit 5199357

Please sign in to comment.