Skip to content

Commit 0fab5c8

Browse files
committed
feat: check epub:type restrictions in XHTML and SVG
This commit refactors the RelaxNG XHTML and SVG schemas to check that the `epub:type` attribute is only allowed on: - palpable content in XHTML - structural, shape, and text elements in SVG It also reorganizes and renames the schemas in a slightly more consistent way. Fixes #1348
1 parent 8631b7d commit 0fab5c8

32 files changed

+700
-358
lines changed

src/main/java/com/adobe/epubcheck/ops/OPSChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public class OPSChecker extends PublicationResourceChecker
5656
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_2)),
5757
XMLValidators.XHTML_20_NVDL, XMLValidators.XHTML_20_SCH, XMLValidators.IDUNIQUE_20_SCH)
5858
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
59-
XMLValidators.XHTML_30_NVDL, XMLValidators.SVG_INFORMATIVE_30_NVDL)
59+
XMLValidators.XHTML_30_NVDL, XMLValidators.SVG_30_INFORMATIVE_NVDL)
6060
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_2)),
6161
XMLValidators.SVG_20_NVDL, XMLValidators.IDUNIQUE_20_SCH)
6262
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_3)),
63-
XMLValidators.SVG_30_NVDL, XMLValidators.SVG_INFORMATIVE_30_NVDL)
63+
XMLValidators.SVG_30_NVDL, XMLValidators.SVG_30_INFORMATIVE_NVDL)
6464
.putAll(
6565
and(or(profile(EPUBProfile.DICT), hasPubType(PublicationType.DICTIONARY)),
6666
mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),

src/main/java/com/adobe/epubcheck/xml/XMLValidators.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public enum XMLValidators
3939
SVG_20_NVDL("schema/20/rng/ops20-svg.nvdl"),
4040
SVG_30_RNC("schema/30/epub-svg-30.rnc"),
4141
SVG_30_NVDL("schema/30/epub-svg-30.nvdl"),
42-
SVG_INFORMATIVE_30_NVDL("schema/30/epub-svg-informative.nvdl", false),
42+
SVG_30_INFORMATIVE_NVDL("schema/30/epub-svg-30-informative.nvdl", false),
4343
SVG_30_SCH("schema/30/epub-svg-30.sch"),
4444
XHTML_20_NVDL("schema/20/rng/ops20.nvdl"),
4545
XHTML_20_SCH("schema/20/sch/xhtml.sch"),

src/main/resources/com/adobe/epubcheck/schema/30/epub-nav-30.rnc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
default namespace = "http://www.w3.org/1999/xhtml"
33
namespace epub = "http://www.idpf.org/2007/ops"
44

5+
6+
# #####################################################################
7+
## RELAX NG Schema for EPUB: EPUB Navigation Documents #
8+
# #####################################################################
9+
510
include "epub-xhtml-30.rnc" {
611
nav.attrs = nav.attrs.noepubtype
712
}

src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-informative.nvdl renamed to src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30-informative.nvdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">
33
<namespace ns="http://www.w3.org/2000/svg">
4-
<validate schema="epub-svg-informative.rnc" schemaType="application/relax-ng-compact-syntax"/>
4+
<validate schema="epub-svg-30-informative.rnc" schemaType="application/relax-ng-compact-syntax"/>
55
</namespace>
66
<namespace ns="" match="attributes">
77
<attach/>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace svg = "http://www.w3.org/2000/svg"
2+
3+
# #####################################################################
4+
## RELAX NG Schema for EPUB: EPUB SVG and XHTML (+ MathML) #
5+
## strict SVG grammar check (informative only) #
6+
# #####################################################################
7+
8+
include "./mod/epub-xhtml-inc.rnc" {
9+
# This schema applies both to XHTML and SVG documents
10+
start = svg | html.elem
11+
}
12+
include "./mod/epub-svg-strict-inc.rnc"
13+
include "./mod/epub-mathml3-inc.rnc"
14+
include "./mod/epub-shared-inc.rnc"
15+
16+
common.elem.phrasing |= svg
17+
common.elem.phrasing |= math
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
namespace svg = "http://www.w3.org/2000/svg"
21

3-
include "./mod/epub-xhtml-inc.rnc" {
2+
# #####################################################################
3+
## RELAX NG Schema for EPUB: EPUB SVG (+ XHTML, + MathML) #
4+
# #####################################################################
5+
6+
include "./mod/epub-xhtml-svg-mathml.rnc" {
47
start = svg
8+
9+
# Override the `id` attribute to require a valid XML ID
10+
svg.attr.id = attribute id { xsd:ID }?
511
}
6-
include "./mod/epub-mathml3.rnc"
7-
include "./mod/epub-svg-inc.rnc"
8-
9-
svg.title.content |= common.inner.anyhtml
10-
11-
svg.foreignObject.content |=
12-
( body.elem
13-
| common.inner.flow
14-
| math
15-
)
1612

17-
mtext.content |= common.elem.phrasing
13+
# Allow `body` element as a child of `foreignObject`
14+
svg.foreignObject.inner |= body.elem

src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-informative.rnc

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
namespace svg = "http://www.w3.org/2000/svg"
21

3-
include "./mod/epub-xhtml-inc.rnc"
4-
include "./mod/epub-mathml3.rnc"
5-
include "./mod/epub-svg-inc.rnc" {
6-
svg.attr.id = attribute id { datatype.html5.token }?
7-
}
2+
# #####################################################################
3+
## RELAX NG Schema for EPUB: EPUB XHTML (+ SVG, + MathML) #
4+
# #####################################################################
85

9-
common.elem.phrasing |= svg
10-
common.elem.phrasing |= math
11-
12-
math.attributes &= aria.global?
13-
14-
svg.title.content |= common.inner.anyhtml
15-
16-
svg.foreignObject.content |=
17-
( common.inner.flow
18-
| math
19-
)
6+
include "./mod/epub-xhtml-svg-mathml.rnc"

src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-mathml3.rnc renamed to src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-mathml3-inc.rnc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ include "mathml/mathml3-inc.rnc" {
2929
# override annotation-xml with EPUB restrictions
3030
annotation-xml = epub.annotation-xml
3131
}
32-
3332
# Common attribute extensions
3433
# - SSML attributes
3534
CommonAtt &= epub.ssml.ph.attr?
3635
# - xml:base
3736
CommonAtt &= common.attrs.xmlbase?
37+
# - ARIA
38+
CommonAtt &= aria.global?
3839

3940
annotation-xml.model.xhtml |= common.inner.flow
4041
annotation-xml.model.svg |= svg
4142

43+
4244
# The following comes from validator.nu’s xhtml5-svg-mathml.rnc driver:
4345
# in our integration, <mtext> is the only MathML "token element" that can
4446
# contain HTML element content; the <mi>, <mn>, <mo> and <ms> elements
@@ -84,4 +86,3 @@ epub.annotation-xml =
8486
attribute name {
8587
xsd:NCName
8688
}
87-
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11

2+
namespace epub = "http://www.idpf.org/2007/ops"
23

3-
namespace epub = "http://www.idpf.org/2007/ops"
4-
5-
html.attrs &= epub.prefix.attr.ns?
6-
7-
epub.prefix.attr = attribute prefix { datatype.prefixdecl }
8-
epub.prefix.attr.ns = attribute epub:prefix { datatype.prefixdecl }
4+
# #####################################################################
5+
## RELAX NG Schema for EPUB: EPUB prefix attributes #
6+
# #####################################################################
7+
8+
## prefix attributes
9+
10+
epub.prefix.attr =
11+
attribute prefix {
12+
datatype.prefixdecl
13+
}
14+
15+
epub.prefix.attr.ns =
16+
attribute epub:prefix {
17+
datatype.prefixdecl
18+
}

0 commit comments

Comments
 (0)