Skip to content

Commit

Permalink
feat: check epub:type restrictions in XHTML and SVG
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rdeltour committed Nov 27, 2022
1 parent 8631b7d commit 0fab5c8
Show file tree
Hide file tree
Showing 32 changed files with 700 additions and 358 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/adobe/epubcheck/ops/OPSChecker.java
Original file line number Diff line number Diff line change
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_NVDL, XMLValidators.SVG_INFORMATIVE_30_NVDL)
XMLValidators.XHTML_30_NVDL, XMLValidators.SVG_30_INFORMATIVE_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_INFORMATIVE_30_NVDL)
XMLValidators.SVG_30_NVDL, XMLValidators.SVG_30_INFORMATIVE_NVDL)
.putAll(
and(or(profile(EPUBProfile.DICT), hasPubType(PublicationType.DICTIONARY)),
mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/adobe/epubcheck/xml/XMLValidators.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +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_INFORMATIVE_NVDL("schema/30/epub-svg-30-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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
default namespace = "http://www.w3.org/1999/xhtml"
namespace epub = "http://www.idpf.org/2007/ops"


# #####################################################################
## RELAX NG Schema for EPUB: EPUB Navigation Documents #
# #####################################################################

include "epub-xhtml-30.rnc" {
nav.attrs = nav.attrs.noepubtype
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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"/>
<validate schema="epub-svg-30-informative.rnc" schemaType="application/relax-ng-compact-syntax"/>
</namespace>
<namespace ns="" match="attributes">
<attach/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace svg = "http://www.w3.org/2000/svg"

# #####################################################################
## RELAX NG Schema for EPUB: EPUB SVG and XHTML (+ MathML) #
## strict SVG grammar check (informative only) #
# #####################################################################

include "./mod/epub-xhtml-inc.rnc" {
# This schema applies both to XHTML and SVG documents
start = svg | html.elem
}
include "./mod/epub-svg-strict-inc.rnc"
include "./mod/epub-mathml3-inc.rnc"
include "./mod/epub-shared-inc.rnc"

common.elem.phrasing |= svg
common.elem.phrasing |= math
23 changes: 10 additions & 13 deletions src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
namespace svg = "http://www.w3.org/2000/svg"

include "./mod/epub-xhtml-inc.rnc" {
# #####################################################################
## RELAX NG Schema for EPUB: EPUB SVG (+ XHTML, + MathML) #
# #####################################################################

include "./mod/epub-xhtml-svg-mathml.rnc" {
start = svg

# Override the `id` attribute to require a valid XML ID
svg.attr.id = attribute id { xsd:ID }?
}
include "./mod/epub-mathml3.rnc"
include "./mod/epub-svg-inc.rnc"

svg.title.content |= common.inner.anyhtml

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

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

This file was deleted.

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

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

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

math.attributes &= aria.global?

svg.title.content |= common.inner.anyhtml

svg.foreignObject.content |=
( common.inner.flow
| math
)
include "./mod/epub-xhtml-svg-mathml.rnc"
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ include "mathml/mathml3-inc.rnc" {
# override annotation-xml with EPUB restrictions
annotation-xml = epub.annotation-xml
}

# Common attribute extensions
# - SSML attributes
CommonAtt &= epub.ssml.ph.attr?
# - xml:base
CommonAtt &= common.attrs.xmlbase?
# - ARIA
CommonAtt &= aria.global?

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


# The following comes from validator.nu’s xhtml5-svg-mathml.rnc driver:
# in our integration, <mtext> is the only MathML "token element" that can
# contain HTML element content; the <mi>, <mn>, <mo> and <ms> elements
Expand Down Expand Up @@ -84,4 +86,3 @@ epub.annotation-xml =
attribute name {
xsd:NCName
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@

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

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

html.attrs &= epub.prefix.attr.ns?

epub.prefix.attr = attribute prefix { datatype.prefixdecl }
epub.prefix.attr.ns = attribute epub:prefix { datatype.prefixdecl }
# #####################################################################
## RELAX NG Schema for EPUB: EPUB prefix attributes #
# #####################################################################

## prefix attributes

epub.prefix.attr =
attribute prefix {
datatype.prefixdecl
}

epub.prefix.attr.ns =
attribute epub:prefix {
datatype.prefixdecl
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# #####################################################################
## RELAX NG Schema for EPUB: shared definitions for inclusion #
# #####################################################################

## Includes

# EPUB elements
include "./epub-trigger.rnc"
include "./epub-switch.rnc"

# EPUB attributes
include "./epub-prefix-attr.rnc"
include "./epub-ssml-attrs.rnc"
include "./epub-type-attr.rnc"

# EPUB integration logic
include "./epub-xhtml-integration.rnc"

## Content model: HTML fragments

# Note: the default HMTL schema does not define such a category, so we
# do our best to include what makes sense here

common.inner.anyhtml =
html.elem
| body.elem
| common.inner.flow

Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@


namespace epub = "http://www.idpf.org/2007/ops"
namespace ssml = "http://www.w3.org/2001/10/synthesis"


common.attrs.other &= epub.ssml.ph.attr? & epub.ssml.alphabet.attr?

#TODO determine injection in SVG

epub.ssml.ph.attr = attribute ssml:ph { datatype.ssml.PhoneticExpression }
epub.ssml.alphabet.attr = attribute ssml:alphabet { datatype.ssml.PhoneticAlphabet }

# #####################################################################
## RELAX NG Schema for EPUB: EPUB SSML attributes #
# #####################################################################


## SSML attributes

epub.ssml.ph.attr =
attribute ssml:ph {
datatype.ssml.PhoneticExpression
}

epub.ssml.alphabet.attr =
attribute ssml:alphabet {
datatype.ssml.PhoneticAlphabet
}
Loading

0 comments on commit 0fab5c8

Please sign in to comment.