Skip to content

Commit

Permalink
Add s-104 and t-076 for possible <dfn> candidates in endnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Jul 13, 2024
1 parent 4ea1530 commit cc86fb0
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
11 changes: 11 additions & 0 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
"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."
"s-104", "[xhtml]<i>[/] element without semantic at beginning of endnote. Hint: Should this be [xhtml]<dfn>[/] instead?"
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 @@ -429,6 +430,7 @@
"t-073", "Possible transcription error in Greek."
"t-074", "Extended sound using hyphen-minus [text]-[/] instead of non-breaking hyphen [text]‑[/]."
"t-075", "Word in verse with acute accent for scansion instead of grave accent."
"t-076", "[xhtml]<dfn>[/] at beginning of endnote should be set in italics."
XHTML
Expand Down Expand Up @@ -1500,6 +1502,15 @@ def _lint_special_file_checks(self, filename: Path, dom: se.easy_xml.EasyXmlTree
if nodes:
messages.append(LintMessage("t-027", "Endnote backlink not preceded by exactly one space.", se.MESSAGE_TYPE_WARNING, filename, [node.to_string() for node in nodes]))

# Check for semantic-less <i> at beginning of endnotes
nodes = dom.xpath("/html/body//li[contains(@epub:type, 'endnote') and ./p/node()[1][name() = 'i' and not(@epub:type) and string-length(.) < 20 and string-length(./following-sibling::text()) > 20]]")
if nodes:
messages.append(LintMessage("s-104", "[xhtml]<i>[/] element without semantic at beginning of endnote. Hint: Should this be [xhtml]<dfn>[/] instead?", se.MESSAGE_TYPE_ERROR, filename, [node.to_string() for node in nodes]))

# <dfn> in endnotes without font-style: italic
if dom.xpath("/html/body//li[contains(@epub:type, 'endnote') and ./p/node()[1][name() = 'dfn' and not(@data-css-font-style = 'italic')]]"):
messages.append(LintMessage("t-076", "[xhtml]<dfn>[/] at beginning of endnote should be set in italics.", se.MESSAGE_TYPE_WARNING, filename))

# Check LoI descriptions to see if they match associated figcaptions
elif special_file == "loi":
for node in dom.xpath("/html/body/nav[contains(@epub:type, 'loi')]//li//a"):
Expand Down
19 changes: 19 additions & 0 deletions tests/lint/semantic/s-104/golden/s-104-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
m-033 [Manual Review] endnotes.xhtml `endnotes` semantic inflection found, but
no MARC relator `ann` (Annotator).
s-056 [Error] endnotes.xhtml Last `<p>` child of endnote missing backlink.
<li epub:type="endnote">
<li epub:type="endnote">
<li epub:type="endnote">
<li epub:type="endnote">
<li epub:type="endnote">
<li epub:type="endnote">
s-104 [Error] endnotes.xhtml `<i>` element without semantic at beginning of
endnote. Hint: Should this be `<dfn>` instead?
<li epub:type="endnote">
<p><i>Cho</i> is generally translated as “street.”</p>
</li>
<li epub:type="endnote">
<p>Some other text.</p>
<p><i>Tsu</i> is an instance of shortening a name in familiar
speech.</p>
</li>
39 changes: 39 additions & 0 deletions tests/lint/semantic/s-104/in/src/epub/text/endnotes.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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>Endnotes</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="backmatter">
<section id="endnotes" epub:type="endnotes">
<h2 epub:type="title">Endnotes</h2>
<ol>
<li epub:type="endnote">
<p><i>Cho</i> is generally translated as “street.”</p>
</li>
<!-- s-104 looks at each <p> within an endnote -->
<li epub:type="endnote">
<p>Some other text.</p>
<p><i>Tsu</i> is an instance of shortening a name in familiar speech.</p>
</li>
<!-- not relevant for s-104 because the <i> has an epub:type -->
<li epub:type="endnote">
<p><i epub:type="se:name.vessel.ship">Nautilus</i> is a submarine.</p>
</li>
<!-- not relevant for s-104 because the <i> text is too long -->
<li epub:type="endnote">
<p><i>012345678901234567891</i> is 21 characters long.</p>
</li>
<!-- not relevant for s-104 because the following text is too short -->
<li epub:type="endnote">
<p><i>X</i> 12345678901234567.</p>
</li>
<!-- not relevant for s-104 because the <i> is not the first child of the <p> -->
<li epub:type="endnote">
<p>An <i>X</i> marked the spot.</p>
</li>
</ol>
</section>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/lint/typography/t-076/golden/t-076-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
m-033 [Manual Review] endnotes.xhtml `endnotes` semantic inflection found, but
no MARC relator `ann` (Annotator).
s-056 [Error] endnotes.xhtml Last `<p>` child of endnote missing backlink.
<li epub:type="endnote">
t-076 [Manual Review] endnotes.xhtml `<dfn>` at beginning of endnote should be
set in italics.
6 changes: 6 additions & 0 deletions tests/lint/typography/t-076/in/src/epub/css/local.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@charset "utf-8";

/* browser.css defaults this to italic, so override it here */
dfn{
font-style: normal;
}
18 changes: 18 additions & 0 deletions tests/lint/typography/t-076/in/src/epub/text/endnotes.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>Endnotes</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="backmatter">
<section id="endnotes" epub:type="endnotes">
<h2 epub:type="title">Endnotes</h2>
<ol>
<li epub:type="endnote">
<p><dfn>Cho</dfn> is generally translated as “street.”</p>
</li>
</ol>
</section>
</body>
</html>

0 comments on commit cc86fb0

Please sign in to comment.