Skip to content

Commit

Permalink
lint: Add s-076, dedication with letter semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
acabal committed Nov 12, 2024
1 parent 8012753 commit 276458f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
"s-073", "Header element that requires [val]label[/] and [val]ordinal[/] semantic children."
"s-074", "[xhtml]<th>[/] element with no text content should be a [xhtml]<td>[/] element instead."
"s-075", "[xhtml]<body>[/] element with direct children that are not [xhtml]<section>[/], [xhtml]<article>[/], or [xhtml]<nav>[/]."
"s-076", "Dedication with letter semantics. Hint: Dedications are never letters, even if they appear to be addressed to someone."
"s-077", "[xhtml]<header>[/] element preceded by non-sectioning element."
"s-078", "[xhtml]<footer>[/] element followed by non-sectioning element."
"s-079", "Element containing only white space."
Expand Down Expand Up @@ -352,9 +353,6 @@
"s-101", "Anonymous primary contributor value not exactly [text]Anonymous[/]."
"s-102", "[attr]lang[/] attribute detected. Hint: Use [attr]xml:lang[/] instead."
"s-103", "Probable missing semantics for a roman I numeral."
UNUSED
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
"s-076", "[attr]lang[/] attribute used instead of [attr]xml:lang[/]."
TYPOGRAPHY
"t-001", "Double spacing found. Sentences should be single-spaced. (Note that double spaces might include Unicode no-break spaces!)"
Expand Down Expand Up @@ -2143,6 +2141,11 @@ def _lint_xhtml_syntax_checks(self, filename: Path, dom: se.easy_xml.EasyXmlTree
if nodes:
messages.append(LintMessage("s-075", "[xhtml]<body>[/] element with direct child that is not [xhtml]<section>[/], [xhtml]<article>[/], or [xhtml]<nav>[/].", se.MESSAGE_TYPE_ERROR, filename))

# Check for dedications with letter semantics
nodes = dom.xpath("/html/body//section[contains(@epub:type, 'dedication') and (descendant-or-self::*[contains(@epub:type, 'z3998:letter')] or .//*[contains(@epub:type, 'z3998:sender')])]")
if nodes:
messages.append(LintMessage("s-076", "Dedication with letter semantics. Hint: Dedications are never letters, even if they appear to be addressed to someone.", se.MESSAGE_TYPE_ERROR, filename))

# Check for <header> preceded by non-sectioning elements
nodes = dom.xpath("/html/body//header[./preceding-sibling::*[not(re:test(name(), '^(section|div|article)$'))]]")
if nodes:
Expand Down

0 comments on commit 276458f

Please sign in to comment.