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

feat: check discouraged HTML elements (base, rp, embed) #1379

Merged
merged 1 commit into from
Dec 5, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private void initialize()
severities.put(MessageId.HTM_052, Severity.ERROR);
severities.put(MessageId.HTM_053, Severity.INFO);
severities.put(MessageId.HTM_054, Severity.ERROR);
severities.put(MessageId.HTM_055, Severity.WARNING);
rdeltour marked this conversation as resolved.
Show resolved Hide resolved

// Media
severities.put(MessageId.MED_001, Severity.ERROR);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public enum MessageId implements Comparable<MessageId>
HTM_052("HTM-052"),
HTM_053("HTM_053"),
HTM_054("HTM_054"),
HTM_055("HTM_055"),

// Messages associated with media (images, audio and video)
MED_001("MED-001"),
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,12 @@ public void startElement()
super.startElement();

XMLElement e = parser.getCurrentElement();
String name = e.getName();

checkDiscouragedElements(e);
processSemantics(e);
processSectioning(e);

String name = e.getName();
if (name.equals("html"))
{
vocabs = VocabUtil.parsePrefixDeclaration(
Expand Down Expand Up @@ -387,6 +388,23 @@ else if ("http://www.w3.org/2000/svg".equals(e.getNamespace()) && name.equals("t

checkSSMLPh(e.getAttributeNS("http://www.w3.org/2001/10/synthesis", "ph"));
}

protected void checkDiscouragedElements(XMLElement elem)
{
if (EpubConstants.HtmlNamespaceUri.equals(elem.getNamespace()))
{
switch (elem.getName())
{
case "base":
case "embed":
case "rp":
report.message(MessageId.HTM_055,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()),
elem.getName());
}

}
}

protected void processInlineScripts(com.adobe.epubcheck.xml.XMLElement e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ HTM_051=Found Microdata semantic enrichments but no RDFa. EDUPUB recommends usin
HTM_052=The property "region-based" is only allowed on nav elements in Data Navigation Documents.
HTM_053=Found an external file link (file://) in file: "%1$s".
HTM_054=Custom attribute namespace ("%1$s") must not include the string "%2$s" in its domain.
HTM_055=The "%1$s" element should not be used (discouraged construct)

#media
MED_001=Video poster must have core media image type.
Expand Down
20 changes: 20 additions & 0 deletions src/test/resources/epub3/content-document-xhtml.feature
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,23 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks
Scenario: Verify RDF elements can be embedded in SVG
When checking document 'svg-rdf-valid.xhtml'
Then no errors or warnings are reported

## Discouraged Constructs

Scenario: Report `base` as a discouraged construct
When checking document 'discouraged-base-warning.xhtml'
Then warning HTM-055 is reported
And the message contains 'base'
And no other errors or warnings are reported

Scenario: Report `embed` as a discouraged construct
When checking document 'discouraged-embed-warning.xhtml'
Then warning HTM-055 is reported
And the message contains 'embed'
And no other errors or warnings are reported

Scenario: Report `rp` as a discouraged construct
When checking document 'discouraged-rp-warning.xhtml'
Then warning HTM-055 is reported 2 times
And the message contains 'rp'
And no other errors or warnings are reported
4 changes: 3 additions & 1 deletion src/test/resources/epub3/content-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks

Scenario: Verify that a base url can be set
When checking EPUB 'content-xhtml-base-url-valid'
Then warning HTM-055 is reported (side effect of `base` being discouraged)
Then no errors or warnings are reported

Scenario: Report relative paths as remote resources when HTML `base` is set to an extenal URL (issue 155)
When checking EPUB 'content-xhtml-base-url-remote-relative-path-error'
Then warning HTM-055 is reported (side effect of `base` being discouraged)
Then error RSC-006 is reported
And no other errors or warnings are reported

Expand Down Expand Up @@ -213,7 +215,7 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks

Scenario: Verify that an SVG image can be referenced from `img`, `object` and `iframe` elements
When checking EPUB 'content-xhtml-svg-reference-valid'
Then no errors or warnings are reported
And no errors or warnings are reported

Scenario: Verify that `svg:switch` doesn't trigger the package document `switch` property check
When checking EPUB 'content-xhtml-svg-switch-valid'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<base href="http://example.org" />
<title>Test</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<embed src="img.svg" type="image/svg+xml"/>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<ruby>漢<rp>(</rp><rt>かん</rt><rp>)</rp></ruby>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<title>Minimal EPUB</title>
</head>
<body>
<embed src="image.svg" type="image/svg+xml"></embed>
<iframe src="image.svg" width="256" height="256"></iframe>
<img src="image.svg" alt="test" />
<img
Expand Down