Skip to content

Commit 6cd9789

Browse files
committed
feat: allow epub:type on SVG renderable elements
Update the SVG schemas to allow the "epub:type" attribute on all renderable elements, as suggested in w3c/epub-specs#2556. Note: this is a willful violation of the EPUB 3.3 spec, which (at the time of writing) only allows the attribute on structural, shape, and text elements. Fix #1497
1 parent 9ffd491 commit 6cd9789

File tree

8 files changed

+79
-79
lines changed

8 files changed

+79
-79
lines changed

src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,32 @@
8383
#
8484
# Note: an element in this list also needs to be added to the
8585
# exception clause in the `svg.anyother.elem` class
86-
svg.structural.elem =
87-
( element defs { svg.any.inner & svg.epubtype.allowed.attrs }
88-
| element g { svg.any.inner & svg.epubtype.allowed.attrs }
89-
| element svg { svg.any.inner & svg.epubtype.allowed.attrs }
90-
| element symbol { svg.any.inner & svg.epubtype.allowed.attrs }
91-
| element use { svg.any.inner & svg.epubtype.allowed.attrs }
92-
)
93-
svg.shape.elem =
94-
( element path { svg.any.inner & svg.epubtype.allowed.attrs }
95-
| element rect { svg.any.inner & svg.epubtype.allowed.attrs }
86+
svg.renderable.elem =
87+
( element a { svg.any.inner & svg.epubtype.allowed.attrs }
88+
| element audio { svg.any.inner & svg.epubtype.allowed.attrs }
89+
| element canvas { svg.any.inner & svg.epubtype.allowed.attrs }
9690
| element circle { svg.any.inner & svg.epubtype.allowed.attrs }
9791
| element ellipse { svg.any.inner & svg.epubtype.allowed.attrs }
92+
| element g { svg.any.inner & svg.epubtype.allowed.attrs }
93+
| element iframe { svg.any.inner & svg.epubtype.allowed.attrs }
94+
| element image { svg.any.inner & svg.epubtype.allowed.attrs }
9895
| element line { svg.any.inner & svg.epubtype.allowed.attrs }
99-
| element polyline { svg.any.inner & svg.epubtype.allowed.attrs }
96+
| element path { svg.any.inner & svg.epubtype.allowed.attrs }
10097
| element polygon { svg.any.inner & svg.epubtype.allowed.attrs }
101-
)
102-
svg.text.elem =
103-
( element text { svg.any.inner & svg.epubtype.allowed.attrs }
104-
| element altGlyph { svg.any.inner & svg.epubtype.allowed.attrs }
98+
| element polyline { svg.any.inner & svg.epubtype.allowed.attrs }
99+
| element rect { svg.any.inner & svg.epubtype.allowed.attrs }
100+
| element svg { svg.any.inner & svg.epubtype.allowed.attrs }
101+
| element switch { svg.any.inner & svg.epubtype.allowed.attrs }
102+
| element symbol { svg.any.inner & svg.epubtype.allowed.attrs }
103+
| element text { svg.any.inner & svg.epubtype.allowed.attrs }
105104
| element textPath { svg.any.inner & svg.epubtype.allowed.attrs }
106-
| element tref { svg.any.inner & svg.epubtype.allowed.attrs }
107105
| element tspan { svg.any.inner & svg.epubtype.allowed.attrs }
106+
| element unknown { svg.any.inner & svg.epubtype.allowed.attrs }
107+
| element use { svg.any.inner & svg.epubtype.allowed.attrs }
108+
| element video { svg.any.inner & svg.epubtype.allowed.attrs }
108109
)
109110
svg.epubtype.allowed.elem =
110-
( svg.structural.elem
111-
| svg.shape.elem
112-
| svg.text.elem
113-
)
111+
( svg.renderable.elem )
114112

115113
### Any other elements
116114

@@ -120,23 +118,28 @@
120118
svg.anyother.elem = element * -
121119
( foreignObject
122120
| title
123-
| defs
124-
| g
125-
| svg
126-
| symbol
127-
| use
128-
| path
129-
| rect
121+
| a
122+
| audio
123+
| canvas
130124
| circle
131125
| ellipse
126+
| g
127+
| iframe
128+
| image
132129
| line
133-
| polyline
130+
| path
134131
| polygon
132+
| polyline
133+
| rect
134+
| svg
135+
| switch
136+
| symbol
135137
| text
136-
| altGlyph
137138
| textPath
138-
| tref
139139
| tspan
140+
| unknown
141+
| use
142+
| video
140143
) { svg.any.inner & svg.epubtype.forbidden.attrs }
141144

142145
### Anything

src/test/resources/epub3/06-content-document/content-document-svg.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Feature: EPUB 3 — Content Documents — SVG
4747
@spec @xref:sec-svg-req
4848
Scenario: Report an `epub:type` attribute used on an element where it is not allowed
4949
When checking document 'epubtype-not-allowed-error.svg'
50-
Then error RSC-005 is reported 3 times
50+
Then error RSC-005 is reported 5 times
5151
And the message contains '"epub:type" not allowed'
5252
And no other errors or warnings are reported
5353

@@ -125,7 +125,7 @@ Feature: EPUB 3 — Content Documents — SVG
125125
### 6.2.3 Restrictions on SVG
126126

127127
#### `foreignObject` element
128-
128+
129129
@spec @xref:sec-svg-restrictions
130130
Scenario: Verify that `foreignObject` conforming to the rules is allowed
131131
When checking document 'foreignObject-valid.svg'

src/test/resources/epub3/06-content-document/content-document-xhtml.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ Feature: EPUB 3 — Content Documents — XHTML
932932

933933
@spec @xref:sec-xhtml-svg @xref:sec-svg-req
934934
Scenario: Verify that `epub:type` attribute can be used on SVG
935-
When checking document 'svg-with-epubtype-valid.xhtml'
935+
When checking document 'svg-epubtype-valid.xhtml'
936936
Then no errors or warnings are reported
937937

938938
Scenario: Verify that SVG validation erors are reported as USAGE
Lines changed: 5 additions & 4 deletions
Loading

src/test/resources/epub3/06-content-document/files/epubtype-valid.svg

Lines changed: 0 additions & 8 deletions
Loading

src/test/resources/epub3/06-content-document/files/epubtype-valid.xhtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
2-
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
3+
lang="en">
34
<head>
45
<meta charset="utf-8" />
56
<title>epub:type with SSV semantics</title>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:x="http://www.w3.org/1999/xhtml"
3+
xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>SVG with epub:type embedded in HTML</title>
7+
</head>
8+
<body>
9+
<section>
10+
<!--epub:type on SVG `svg` element-->
11+
<svg xmlns="http://www.w3.org/2000/svg" epub:type="titlepage"
12+
viewBox="0 0 100 100" version="1.1">
13+
<desc>Test</desc>
14+
</svg>
15+
16+
<!--epub:type on SVG `g` element-->
17+
<svg xmlns="http://www.w3.org/2000/svg"
18+
viewBox="0 0 100 100" version="1.1">
19+
<desc>Test</desc>
20+
<circle cx="50" cy="50" r="50"/>
21+
<g epub:type="notice">
22+
<circle cx="50" cy="50" r="50"/>
23+
</g>
24+
</svg>
25+
26+
<!--epub:type on SVG `a` element-->
27+
<svg xmlns="http://www.w3.org/2000/svg"
28+
viewBox="0 0 100 100" version="1.1">
29+
<desc>Test</desc>
30+
<a epub:type="noteref" href="#note" id="ref">
31+
</a>
32+
</svg>
33+
<p id="note">a note</p>
34+
</section>
35+
</body>
36+
</html>

src/test/resources/epub3/06-content-document/files/svg-with-epubtype-valid.xhtml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)