Skip to content

Commit

Permalink
feat: basic schema support for HTML custom elements
Browse files Browse the repository at this point in the history
- add an `isCustomElement` method in `HTMLUtils`.
- pre-process custom elements in `XMLParser` to put them in the
  proprietary namespace used by the Nu Html Checker schemas to treat
  them distinctively.
- add a simple test case.

Fix #932
  • Loading branch information
rdeltour committed Feb 8, 2019
1 parent 5b3533a commit 356fac0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/com/adobe/epubcheck/xml/HTMLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public static boolean isCaseInsensitiveAttribute(String name)

}

public static boolean isCustomElement(String namespace, String name)
{
return Namespaces.XHTML.equals(namespace) && Preconditions.checkNotNull(name).contains("-");
}

}
10 changes: 9 additions & 1 deletion src/main/java/com/adobe/epubcheck/xml/XMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,16 @@ public void startElement(String namespaceURI, String localName, String qName,
Attributes parsedAttribs)
throws SAXException
{

Attributes attribs = preprocessAttributes(namespaceURI, localName, qName, parsedAttribs);

if ("application/xhtml+xml".equals(context.mimeType)
&& context.version == EPUBVersion.VERSION_3) {
// Pre-process HTML custom elements to set them in the proprietary namespace supported
// by the Nu Html Checker
if (HTMLUtils.isCustomElement(namespaceURI, localName)) {
namespaceURI = "http://n.validator.nu/custom-elements/";
}
}

int vlen = validatorContentHandlers.size();
for (int i = 0; i < vlen; i++)
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,14 @@ public void testAttributesCaseInsensitive()
EPUBVersion.VERSION_3);
}

@Test
public void testCustomElements()
{
// test that HTML custom elements are not rejected by the schema
testValidateDocument("xhtml/valid/custom-elements.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

@Test
public void testValidateXHTML301AriaDescribedAt()
{
Expand Down
16 changes: 16 additions & 0 deletions src/test/resources/30/single/xhtml/valid/custom-elements.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Test</h1>
<epub-switch>
<epub-case required-namespace="https://example.org"> oh my! </epub-case>
<epub-default>
<p>is this real?</p>
</epub-default>
</epub-switch>
</body>
</html>

0 comments on commit 356fac0

Please sign in to comment.