Skip to content

Commit

Permalink
feat: do not check conformance of SVG content
Browse files Browse the repository at this point in the history
EPUB 3.3 no longer requires that SVG content conforms to SVG content model requirements,
only that they are well-formed, that ID are uniques, and that they respect some additional
EPUB-specific requirements.

This commit:
  * introduces a new permissive RelaxNG schema for SVG, checking only the EPUB-specific
    requirements on the `title` and `foreignObject` content model
    see w3c/epub-specs#1323
  * removes checks on the value of the `requiredExtensions` attribute of `foreignObject`
    see w3c/epub-specs#1087
  * adapts the main XHTML to SVG schema driver to the new permissive SVG schema
  * adds various tests for EPUB-specific requirements
  • Loading branch information
rdeltour committed Nov 14, 2021
1 parent a2e3a77 commit ba48aaa
Show file tree
Hide file tree
Showing 39 changed files with 437 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<namespace ns="http://www.w3.org/2000/svg">
<validate schema="epub-svg-30.rnc" schemaType="application/relax-ng-compact-syntax"
useMode="allowForeignNS">
<context path="foreignObject" useMode="allowHTMLOnly"/>
<context path="foreignObject" useMode="attachAnyNS"/>
</validate>
<validate schema="epub-svg-30.sch" useMode="attachAnyNS"/>
</namespace>
Expand All @@ -29,23 +29,6 @@
<allow/>
</anyNamespace>
</mode>
<mode name="allowHTMLOnly">
<namespace ns="http://www.w3.org/1999/xhtml">
<attach/>
</namespace>
<namespace ns="http://www.idpf.org/2007/ops" match="attributes">
<attach/>
</namespace>
<namespace ns="http://www.w3.org/1999/xlink" match="attributes">
<attach/>
</namespace>
<namespace ns="http://www.w3.org/XML/1998/namespace" match="attributes">
<attach/>
</namespace>
<namespace ns="" match="attributes">
<attach/>
</namespace>
</mode>
<mode name="attachAnyNS">
<anyNamespace>
<attach/>
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
include "./mod/epub-svg11.rnc"
namespace svg = "http://www.w3.org/2000/svg"

include "./mod/epub-xhtml.rnc" {
start = svg
}
include "./mod/epub-mathml3.rnc"
include "./mod/epub-svg-inc.rnc"

svg.title.content |= common.elem.phrasing

svg.foreignObject.content |=
( body.elem
| common.inner.flow
| math
)

mtext.content |= common.elem.phrasing
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">

<ns uri="http://www.w3.org/2000/svg" prefix="svg" />

<pattern></pattern>
<include href="./mod/id-unique.sch"/>
<include href="./mod/epub-svg11-re.sch"/>

</schema>

18 changes: 14 additions & 4 deletions src/main/resources/com/adobe/epubcheck/schema/30/epub-xhtml-30.rnc
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
## XHTML5
namespace svg = "http://www.w3.org/2000/svg"

include "./mod/epub-xhtml.rnc"
include "./mod/epub-mathml3.rnc"
include "./mod/epub-svg-inc.rnc" {
svg.attr.id = attribute id { datatype.html5.token }?
}

common.elem.phrasing |= svg
common.elem.phrasing |= math

## SVG and MathML
svg.title.content |= common.elem.phrasing

include "./mod/epub-xhtml-mathml3.rnc"
include "./mod/epub-xhtml-svg11.rnc"
svg.foreignObject.content |=
( common.inner.flow
| math
)
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,4 @@
</rule>
</pattern>

<include href="./mod/epub-svg11-re.sch"/>

</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@
uri="mod/epub-ssml-attrs.rnc"/>
<system systemId="epub-ssml-attrs.rnc" uri="mod/epub-ssml-attrs.rnc"/>

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

<system systemId="http://www.idpf.org/epub/30/schema/mod/epub-svg11-re.sch"
uri="mod/epub-svg11-re.sch"/>
<system systemId="epub-svg11-re.sch" uri="mod/epub-svg11-re.sch"/>
<system systemId="http://www.idpf.org/epub/30/schema/mod/epub-svg-inc.rnc"
uri="mod/epub-svg-inc.rnc"/>
<system systemId="epub-svg-inc.rnc" uri="mod/epub-svg-inc.rnc"/>

<system systemId="http://www.idpf.org/epub/30/schema/mod/epub-switch.rnc"
uri="mod/epub-switch.rnc"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
default namespace = "http://www.w3.org/2000/svg"

# #####################################################################
## Anything-goes schema for svg #
# #####################################################################

## SVG root
svg = svg.elem
svg.elem =
element svg { any.content & any.attr }

## Special cases
specific.elems =
( svg.foreignObject
| svg.title
)
specific.attrs = svg.attr.id

### SVG ID datatype
svg.attr.id = attribute id { xsd:ID }?

### SVG foreignObject element restrictions
svg.foreignObject =
element foreignObject { any.attr & svg.foreignObject.content }
svg.foreignObject.content = notAllowed

### SVG title element restrictions
svg.title =
element title { any.attr & svg.title.content }
svg.title.content = text

## Anything

## Any attribute from any namespace, other than the special cases
any.attr = attribute * -id { text }* & svg.attr.id
## Any element from any namespace, other than the special cases
any.elem = element * - (foreignObject|title) { any.content & any.attr }
## Any content from any namespace
any.content = text & any.elem* & specific.elems*

This file was deleted.

This file was deleted.

57 changes: 47 additions & 10 deletions src/test/resources/epub3/content-document-svg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: EPUB 3 ▸ Content Documents ▸ SVG Document Checks
## 3.2 Content Conformance

### ARIA attributes

Scenario: Verify ARIA attributes are allowed
When checking document 'aria-attributes-valid.svg'
Then no errors or warnings are reported
Expand Down Expand Up @@ -65,6 +65,12 @@ Feature: EPUB 3 ▸ Content Documents ▸ SVG Document Checks
And the message contains 'Duplicate'
And no other errors or warnings are reported

Scenario: Report invalid `id` attribute values
When checking document 'id-invalid-error.svg'
Then error RSC-005 is reported
And the message contains '"id" is invalid'
And no other errors or warnings are reported

### Style Attribute

Scenario: Verify `style` element without explicit `type` (issue 688)
Expand All @@ -84,20 +90,51 @@ Feature: EPUB 3 ▸ Content Documents ▸ SVG Document Checks
When checking document 'foreignObject-valid.svg'
Then no errors or warnings are reported

Scenario: Report `foreignObject` with a `requiredExtensions` attribute with a non-OPS namespace
When checking document 'foreignObject-requiredExtensions-ns-error.svg'
Scenario: Verify that the `requiredExtensions` attribute can have any value
Note: 'requiredExensions' was required to be set to 'http://www.idpf.org/2007/ops' in EPUB 3.2 and earlier versions
When checking document 'foreignObject-requiredExtensions-valid.svg'
Then no errors or warnings are reported

Scenario: Report `foreignObject` with non-HTML child content
When checking document 'foreignObject-not-html-error.svg'
Then error RSC-005 is reported
And the message contains 'Invalid value (expecting: "http://www.idpf.org/2007/ops")'
And the message contains 'element "foo" not allowed here'
And no other errors or warnings are reported
Scenario: Report `foreignObject` with non-HTML child content
When checking document 'foreignObject-non-html-content-error.svg'

Scenario: Report `foreignObject` with non-flow content
When checking document 'foreignObject-not-flow-content-error.svg'
Then error RSC-005 is reported
And the message contains 'elements from namespace "https://example.org" are not allowed'
And the message contains 'element "title" not allowed here'
And no other errors or warnings are reported

Scenario: Report `foreignObject` with multiple HTML `body` elements
When checking document 'foreignObject-multiple-body-error.svg'
Then error RSC-005 is reported
And the message contains 'element "h:body" not allowed here'
And the message contains 'element "body" not allowed here'
And no other errors or warnings are reported

Scenario: Report HTML validation errors within `foreignObject` content
When checking document 'foreignObject-html-invalid-error.svg'
Then error RSC-005 is reported
And the message contains 'attribute "href" not allowed here'
And no other errors or warnings are reported

Scenario: Verify `title` can contain text
When checking document 'title-text-valid.svg'
Then no errors or warnings are reported

Scenario: Verify `title` can contain HTML phrasing content
When checking document 'title-phrasing-content-valid.svg'
Then no errors or warnings are reported

Scenario: Report `title` with non-phrasing content
When checking document 'title-not-phrasing-content-error.svg'
Then error RSC-005 is reported
And the message contains 'element "h1" not allowed here'
And no other errors or warnings are reported

Scenario: Report HTML validation errors within `title` content
When checking document 'title-html-invalid-error.svg'
Then error RSC-005 is reported
And the message contains 'attribute "href" not allowed here'
And no other errors or warnings are reported
68 changes: 48 additions & 20 deletions src/test/resources/epub3/content-document-xhtml.feature
Original file line number Diff line number Diff line change
Expand Up @@ -710,26 +710,25 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks
When checking document 'svg-valid.xhtml'
Then no errors or warnings are reported

Scenario: Verify conforming SVG markup does not create false-positives
When checking document 'svg-regression-valid.xhtml'
Then no errors or warnings are reported
Scenario: Verify the SVG IDs can be any valid HTML ID
When checking document 'svg-id-valid.xhtml'
Then no errors or warnings are reported

Scenario: Verify that `epub:type` attribute can be used on SVG
When checking document 'svg-with-epubtype-valid.xhtml'
Then no errors or warnings are reported

Scenario: Report SVG with invalid content model
When checking document 'svg-error.xhtml'
Then error RSC-005 is reported
And the message contains 'The svg element must not appear inside title elements'
And no other errors or warnings are reported

Scenario: Report SVG with incorrect `requiredExtensions` attribute value
When checking document 'svg-requiredExtensions-error.xhtml'
Then error RSC-005 is reported
And the message contains 'Invalid value (expecting: "http://www.idpf.org/2007/ops")'
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'
And no other errors or warnings are reported

Scenario: Verify `xlink:href` allowed on SVG elements
When checking document 'svg-links-valid.xhtml'
Then no errors or warnings are reported

#TODO review if this warning is relevant
Scenario: Report an SVG link without a recommended title
When checking document 'svg-links-no-title-warning.xhtml'
Then warning ACC-011 is reported
Expand All @@ -739,19 +738,48 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks
When checking document 'svg-foreignObject-valid.xhtml'
Then no errors or warnings are reported

Scenario: Report `foreignObject` with disallowed body element
Scenario: Verify that the `requiredExtensions` attribute can have any value
When checking document 'svg-foreignObject-requiredExtensions-valid.xhtml'
And no other errors or warnings are reported

Scenario: Report `foreignObject` with a body element
When checking document 'svg-foreignObject-with-body-error.xhtml'
Then error RSC-005 is reported
And the message contains 'element "body" not allowed here'
And no other errors or warnings are reported

Scenario: Report HTML validation errors within `foreignObject` content
When checking document 'svg-foreignObject-html-invalid-error.xhtml'
Then error RSC-005 is reported
And the message contains 'attribute "href" not allowed here'
And no other errors or warnings are reported

Scenario: Report `foreignObject` without flow content
When checking document 'svg-foreignObject-no-flow-error.xhtml'
When checking document 'svg-foreignObject-not-flow-content-error.xhtml'
Then error RSC-005 is reported
And the message contains 'element "title" not allowed here'
And no other errors or warnings are reported

# Still not allowed by epubcheck - https://github.com/w3c/epubcheck/issues/173
# Scenario: Verify RDF elements can be embedded in SVG
# When checking document 'svg-rdf-valid.xhtml'
# Then no errors or warnings are reported
Scenario: Verify `title` can contain text
When checking document 'svg-title-text-valid.xhtml'
Then no errors or warnings are reported

Scenario: Verify `title` can contain HTML phrasing content
When checking document 'svg-title-phrasing-content-valid.xhtml'
Then no errors or warnings are reported

Scenario: Report `title` with non-phrasing content
When checking document 'svg-title-not-phrasing-content-error.xhtml'
Then error RSC-005 is reported
And the message contains 'element "h1" not allowed here'
And no other errors or warnings are reported

Scenario: Report HTML validation errors within `title` content
When checking document 'svg-title-html-invalid-error.xhtml'
Then error RSC-005 is reported
And the message contains 'attribute "href" not allowed here'
And no other errors or warnings are reported

Scenario: Verify RDF elements can be embedded in SVG
When checking document 'svg-rdf-valid.xhtml'
Then no errors or warnings are reported
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ba48aaa

Please sign in to comment.