Skip to content

Commit

Permalink
feat: enable informative (USAGE) checking of SVG content conformance
Browse files Browse the repository at this point in the history
This commit re-enables SVG content conformance checking:
  * new NVDL and RelaxNG schema drivers will only check SVG content, and ignore other
    namespaces.
  * these informative schemas are enabled for both SVG and XHTML Content Documents
  * SVG content conformance, as before, is using RelaxNG schemas from the Nu HTML Checker.
  • Loading branch information
rdeltour committed Nov 14, 2021
1 parent a2516f0 commit b9ddf8f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/adobe/epubcheck/ops/OPSChecker.java
Expand Up @@ -56,11 +56,11 @@ public class OPSChecker extends PublicationResourceChecker
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_2)),
XMLValidators.XHTML_20_NVDL, XMLValidators.XHTML_20_SCH, XMLValidators.IDUNIQUE_20_SCH)
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
XMLValidators.XHTML_30_RNC, XMLValidators.XHTML_30_SCH)
XMLValidators.XHTML_30_RNC, XMLValidators.XHTML_30_SCH, XMLValidators.SVG_INFORMATIVE_30_NVDL)
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_2)),
XMLValidators.SVG_20_NVDL, XMLValidators.IDUNIQUE_20_SCH)
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_3)),
XMLValidators.SVG_30_NVDL)
XMLValidators.SVG_30_NVDL, XMLValidators.SVG_INFORMATIVE_30_NVDL)
.putAll(
and(or(profile(EPUBProfile.DICT), hasPubType(OPFData.DC_TYPE_DICT)),
mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/xml/XMLValidators.java
Expand Up @@ -39,6 +39,7 @@ public enum XMLValidators
SVG_20_NVDL("schema/20/rng/ops20-svg.nvdl"),
SVG_30_RNC("schema/30/epub-svg-30.rnc"),
SVG_30_NVDL("schema/30/epub-svg-30.nvdl"),
SVG_INFORMATIVE_30_NVDL("schema/30/epub-svg-informative.nvdl", false),
SVG_30_SCH("schema/30/epub-svg-30.sch"),
XHTML_20_NVDL("schema/20/rng/ops20.nvdl"),
XHTML_20_SCH("schema/20/sch/xhtml.sch"),
Expand Down
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">
<namespace ns="http://www.w3.org/2000/svg">
<validate schema="epub-svg-informative.rnc" schemaType="application/relax-ng-compact-syntax"/>
</namespace>
<namespace ns="" match="attributes">
<attach/>
</namespace>
<anyNamespace match="elements attributes">
<allow/>
</anyNamespace>
</rules>
@@ -0,0 +1,30 @@
namespace svg = "http://www.w3.org/2000/svg"

include "./mod/epub-xhtml.rnc" {
# This schema applies both to XHTML and SVG documents
start = svg | html.elem
}
include "./mod/svg11/svg11-inc.rnc" {
# ID datatype is set here to the lower HTML requirements,
# proper checking is done by the normative schema
SVG.id.attrib = attribute id { datatype.html5.token }?
}
include "./mod/svg11/inkscape.rnc"

## EPUB-specific additions:

SVG.Core.attrib &= aria.global?
SVG.Core.extra.attrib &= epub.type.attr?

## Do not check restricted elements, they are checked in normative schemas
SVG.foreignObject.content |= any.content
SVG.title.content |= any.content

## Anything

## Any attribute from any namespace, other than the special cases
any.attr = attribute * { text }*
## Any element from any namespace, other than the special cases
any.elem = element * { any.content & any.attr }
## Any content from any namespace
any.content = text & any.elem*
Expand Up @@ -18,6 +18,12 @@
<system systemId="http://www.idpf.org/epub/30/schema/epub-svg-30.sch"
uri="epub-svg-30.sch"/>

<system systemId="http://www.idpf.org/epub/30/schema/epub-svg-informative.nvdl"
uri="epub-svg-informative.nvdl"/>

<system systemId="http://www.idpf.org/epub/30/schema/epub-svg-informative.rnc"
uri="epub-svg-informative.rnc"/>

<system systemId="http://www.idpf.org/epub/30/schema/epub-xhtml-30.nvdl"
uri="epub-xhtml-30.nvdl"/>

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/epub3/content-document-xhtml.feature
Expand Up @@ -724,8 +724,8 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks
Scenario: Verify that SVG validation erors are reported as USAGE
Given the reporting level set to usage
When checking document 'svg-invalid-usage.xhtml'
#Then usage SVG-000 is reported
#And the message contains 'element "foo" not allowed here'
Then usage RSC-025 is reported
And the message contains 'element "foo" not allowed here'
And no other errors or warnings are reported

#TODO review if this warning is relevant
Expand Down

0 comments on commit b9ddf8f

Please sign in to comment.