Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint: checks and test for missing CSS #613

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N
local_css_has_hymn_style = False
local_css_has_lyrics_style = False
local_css_has_elision_style = False
local_css_has_dedication_style = False
local_css_has_epigraph_style = False
short_story_count = 0
missing_styles: List[str] = []
directories_not_url_safe = []
Expand Down Expand Up @@ -852,6 +854,12 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N
if "span.elision" in selector:
local_css_has_elision_style = True

if "dedication" in selector:
local_css_has_dedication_style = True

if "epigraph" in selector:
local_css_has_epigraph_style = True

if "abbr" in selector and "nowrap" in rules:
abbr_with_whitespace.append(selector)

Expand Down Expand Up @@ -3065,6 +3073,15 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N
if nodes:
messages.append(LintMessage("s-047", "[val]noteref[/] as a direct child of element with poem or verse semantic. [val]noteref[/]s should be in their parent [xhtml]<span>[/].", se.MESSAGE_TYPE_ERROR, filename, [node.to_string() for node in nodes]))

# Record missing styles for front matter
if filename.name not in IGNORED_FILENAMES:
nodes = dom.xpath("/html/body//*[re:test(@epub:type, 'dedication|epigraph')]")
for node in nodes:
if "dedication" in node.get_attr("epub:type") and not local_css_has_dedication_style:
missing_styles.append(node.to_tag_string())
if "epigraph" in node.get_attr("epub:type") and not local_css_has_epigraph_style:
missing_styles.append(node.to_tag_string())

# Check for space before endnote backlinks
if dom.xpath("/html/body/section[contains(@epub:type, 'endnotes')]"):
# Check that citations at the end of endnotes are in a <cite> element. If not typogrify will run the last space together with the em dash.
Expand Down
64 changes: 64 additions & 0 deletions tests/data/lint/c-006-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
s-033 [Manual Review] chapter-1.xhtml File language is `en-GB`, but
`content.opf` language is `LANG`.
m-036 [Error] colophon.xhtml Variable not replaced with value.
PG_URL
IA_URL
COVER_ARTIST
COVER_ARTIST_WIKI_URL
PRODUCER
PRODUCER_URL
YEAR
PG_YEAR
TRANSCRIBER_1
TRANSCRIBER_2
PAINTING
t-064 [Manual Review] colophon.xhtml Title not correctly titlecased. Hint:
Non-English titles should have an `xml:lang` attribute as they have different
titlecasing rules.
<i epub:type="se:name.visual-art.painting">PAINTING</i>
m-036 [Error] content.opf Variable not replaced with value.
SUBJECT_1
SUBJECT_2
LCSH_ID_1
LCSH_ID_2
TAG
DESCRIPTION
LONG_DESCRIPTION
LANG
PG_URL
PRODUCTION_NOTES
EBOOK_WIKI_URL
AUTHOR_SORT
AUTHOR_FULL_NAME
COVER_ARTIST
COVER_ARTIST_SORT
COVER_ARTIST_WIKI_URL
COVER_ARTIST_NACOAF_URI
TRANSCRIBER
TRANSCRIBER_SORT
TRANSCRIBER_URL
PRODUCER
PRODUCER_SORT
PRODUCER_URL
s-020 [Error] content.opf Frontmatter found, but no half title page. Half title
page is required when frontmatter is present.
m-063 [Error] cover.svg Cover image has not been built.
s-033 [Manual Review] dedication.xhtml File language is `en-GB`, but
`content.opf` language is `LANG`.
s-033 [Manual Review] epigraph.xhtml File language is `en-US`, but `content.opf`
language is `LANG`.
m-036 [Error] imprint.xhtml Variable not replaced with value.
PG_URL
IA_URL
c-006 [Error] local.css Semantic found, but missing corresponding style in
`local.css`.
<abbr epub:type="se:era">
<abbr epub:type="se:temperature">
<abbr epub:type="z3998:acronym">
<blockquote epub:type="z3998:hymn">
<blockquote epub:type="z3998:lyrics">
<blockquote epub:type="z3998:poem">
<blockquote epub:type="z3998:verse">
<section id="dedication" epub:type="dedication">
<section id="epigraph" epub:type="epigraph">
<span class="elision">
44 changes: 44 additions & 0 deletions tests/data/lint/c-006/chapter-1.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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>I</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-1" epub:type="chapter">
<h2 epub:type="ordinal z3998:roman">I</h2>
<p>The following abbreviations need CSS styles: <abbr epub:type="se:era">AD</abbr>, <abbr epub:type="se:temperature">C</abbr>, <abbr epub:type="z3998:acronym">A.B.C.</abbr>.</p>
<blockquote epub:type="z3998:hymn">
<p>
<span>Line 1</span>
<br/>
<span class="elision">⋮</span>
<br/>
<span>Line 2</span>
</p>
</blockquote>
<blockquote epub:type="z3998:lyrics">
<p>
<span>Line 1</span>
<br/>
<span>Line 2</span>
</p>
</blockquote>
<blockquote epub:type="z3998:poem">
<p>
<span>Line 1</span>
<br/>
<span>Line 2</span>
</p>
</blockquote>
<blockquote epub:type="z3998:verse">
<p>
<span>Line 1</span>
<br/>
<span>Line 2</span>
</p>
</blockquote>
</section>
</body>
</html>
13 changes: 13 additions & 0 deletions tests/data/lint/c-006/dedication.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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>Dedication</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="frontmatter z3998:non-fiction">
<section id="dedication" epub:type="dedication">
<p>Dedication.</p>
</section>
</body>
</html>
16 changes: 16 additions & 0 deletions tests/data/lint/c-006/epigraph.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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-US">
<head>
<title>Epigraph</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="frontmatter">
<section id="epigraph" epub:type="epigraph">
<blockquote>
<p>Quotation</p>
<cite>Author</cite>
</blockquote>
</section>
</body>
</html>
Empty file added tests/data/lint/c-006/local.css
Empty file.
2 changes: 1 addition & 1 deletion tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from helpers import assemble_book, run, output_is_golden


@pytest.mark.parametrize("test_name", ["clean", "content", "s-058", "glossaries", "elements"])
@pytest.mark.parametrize("test_name", ["c-006", "clean", "content", "s-058", "glossaries", "elements"])
def test_lint(data_dir: Path, draft_dir: Path, work_dir: Path, capfd, test_name: str, update_golden: bool):
"""Run lint command on several books with different expected lint output:
clean - No errors expected
Expand Down