Skip to content

Commit

Permalink
feat: allow epub:type on SVG renderable elements
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rdeltour committed Apr 28, 2023
1 parent 9ffd491 commit 6cd9789
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,32 @@
#
# Note: an element in this list also needs to be added to the
# exception clause in the `svg.anyother.elem` class
svg.structural.elem =
( element defs { svg.any.inner & svg.epubtype.allowed.attrs }
| element g { svg.any.inner & svg.epubtype.allowed.attrs }
| element svg { svg.any.inner & svg.epubtype.allowed.attrs }
| element symbol { svg.any.inner & svg.epubtype.allowed.attrs }
| element use { svg.any.inner & svg.epubtype.allowed.attrs }
)
svg.shape.elem =
( element path { svg.any.inner & svg.epubtype.allowed.attrs }
| element rect { svg.any.inner & svg.epubtype.allowed.attrs }
svg.renderable.elem =
( element a { svg.any.inner & svg.epubtype.allowed.attrs }
| element audio { svg.any.inner & svg.epubtype.allowed.attrs }
| element canvas { svg.any.inner & svg.epubtype.allowed.attrs }
| element circle { svg.any.inner & svg.epubtype.allowed.attrs }
| element ellipse { svg.any.inner & svg.epubtype.allowed.attrs }
| element g { svg.any.inner & svg.epubtype.allowed.attrs }
| element iframe { svg.any.inner & svg.epubtype.allowed.attrs }
| element image { svg.any.inner & svg.epubtype.allowed.attrs }
| element line { svg.any.inner & svg.epubtype.allowed.attrs }
| element polyline { svg.any.inner & svg.epubtype.allowed.attrs }
| element path { svg.any.inner & svg.epubtype.allowed.attrs }
| element polygon { svg.any.inner & svg.epubtype.allowed.attrs }
)
svg.text.elem =
( element text { svg.any.inner & svg.epubtype.allowed.attrs }
| element altGlyph { svg.any.inner & svg.epubtype.allowed.attrs }
| element polyline { svg.any.inner & svg.epubtype.allowed.attrs }
| element rect { svg.any.inner & svg.epubtype.allowed.attrs }
| element svg { svg.any.inner & svg.epubtype.allowed.attrs }
| element switch { svg.any.inner & svg.epubtype.allowed.attrs }
| element symbol { svg.any.inner & svg.epubtype.allowed.attrs }
| element text { svg.any.inner & svg.epubtype.allowed.attrs }
| element textPath { svg.any.inner & svg.epubtype.allowed.attrs }
| element tref { svg.any.inner & svg.epubtype.allowed.attrs }
| element tspan { svg.any.inner & svg.epubtype.allowed.attrs }
| element unknown { svg.any.inner & svg.epubtype.allowed.attrs }
| element use { svg.any.inner & svg.epubtype.allowed.attrs }
| element video { svg.any.inner & svg.epubtype.allowed.attrs }
)
svg.epubtype.allowed.elem =
( svg.structural.elem
| svg.shape.elem
| svg.text.elem
)
( svg.renderable.elem )

### Any other elements

Expand All @@ -120,23 +118,28 @@
svg.anyother.elem = element * -
( foreignObject
| title
| defs
| g
| svg
| symbol
| use
| path
| rect
| a
| audio
| canvas
| circle
| ellipse
| g
| iframe
| image
| line
| polyline
| path
| polygon
| polyline
| rect
| svg
| switch
| symbol
| text
| altGlyph
| textPath
| tref
| tspan
| unknown
| use
| video
) { svg.any.inner & svg.epubtype.forbidden.attrs }

### Anything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Feature: EPUB 3 — Content Documents — SVG
@spec @xref:sec-svg-req
Scenario: Report an `epub:type` attribute used on an element where it is not allowed
When checking document 'epubtype-not-allowed-error.svg'
Then error RSC-005 is reported 3 times
Then error RSC-005 is reported 5 times
And the message contains '"epub:type" not allowed'
And no other errors or warnings are reported

Expand Down Expand Up @@ -125,7 +125,7 @@ Feature: EPUB 3 — Content Documents — SVG
### 6.2.3 Restrictions on SVG

#### `foreignObject` element

@spec @xref:sec-svg-restrictions
Scenario: Verify that `foreignObject` conforming to the rules is allowed
When checking document 'foreignObject-valid.svg'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ Feature: EPUB 3 — Content Documents — XHTML

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

Scenario: Verify that SVG validation erors are reported as USAGE
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
lang="en">
<head>
<meta charset="utf-8" />
<title>epub:type with SSV semantics</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:x="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>SVG with epub:type embedded in HTML</title>
</head>
<body>
<section>
<!--epub:type on SVG `svg` element-->
<svg xmlns="http://www.w3.org/2000/svg" epub:type="titlepage"
viewBox="0 0 100 100" version="1.1">
<desc>Test</desc>
</svg>

<!--epub:type on SVG `g` element-->
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100" version="1.1">
<desc>Test</desc>
<circle cx="50" cy="50" r="50"/>
<g epub:type="notice">
<circle cx="50" cy="50" r="50"/>
</g>
</svg>

<!--epub:type on SVG `a` element-->
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100" version="1.1">
<desc>Test</desc>
<a epub:type="noteref" href="#note" id="ref">
</a>
</svg>
<p id="note">a note</p>
</section>
</body>
</html>

This file was deleted.

0 comments on commit 6cd9789

Please sign in to comment.