Skip to content

Commit

Permalink
fix: allow foreign namespaces in EPUB 2 SVGs
Browse files Browse the repository at this point in the history
* allow foreign namespaced elements and attributes in EPUB 2 SVGs
* Remove the restriction to HTML on foreignObject as that is an epub 3-specific rule
  • Loading branch information
mattgarrish committed Jun 22, 2020
1 parent 929806b commit e3ffc37
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/adobe/epubcheck/ops/OPSChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class OPSChecker implements ContentChecker, DocumentValidator
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
XMLValidators.XHTML_30_RNC, XMLValidators.XHTML_30_SCH)
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_2)),
XMLValidators.SVG_20_RNG, XMLValidators.IDUNIQUE_20_SCH)
XMLValidators.SVG_20_NVDL, XMLValidators.IDUNIQUE_20_SCH)
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_3)),
XMLValidators.SVG_30_NVDL)
.putAll(
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 @@ -36,7 +36,7 @@ public enum XMLValidators
SEARCH_KEY_MAP_RNC("schema/30/dict/search-key-map.rnc"),
SIG_20_RNG("schema/20/rng/signatures.rng"),
SIG_30_RNC("schema/30/ocf-signatures-30.rnc"),
SVG_20_RNG("schema/20/rng/svg11.rng"),
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_30_SCH("schema/30/epub-svg-30.sch"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="svg">
<mode name="svg">
<namespace ns="http://www.w3.org/2000/svg">
<validate schema="svg11.rng" schemaType="application/relax-ng"
useMode="allowForeignNS">
</validate>
</namespace>
</mode>
<mode name="allowForeignNS">
<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>
<anyNamespace match="elements attributes">
<allow/>
</anyNamespace>
</mode>
</rules>
26 changes: 23 additions & 3 deletions src/main/resources/com/adobe/epubcheck/schema/20/rng/ops20.nvdl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- mode that allows arbitrary XHTML or SVG fragment -->
<mode name="blessed-xhtml-svg">
<namespace ns="http://www.w3.org/2000/svg">
<allow/>
<allow useMode="allowForeignNS"/>
</namespace>
<namespace ns="http://www.w3.org/1999/xhtml">
<allow/>
Expand All @@ -27,7 +27,7 @@
<attach/>
</namespace>
<namespace ns="http://www.w3.org/2000/svg">
<attach/>
<attach useMode="allowForeignNS"/>
</namespace>
<anyNamespace>
<allow/>
Expand All @@ -46,7 +46,7 @@
<!-- mode that validates SVG and OPS islands inside XHTML -->
<mode name="xhtml-content">
<namespace ns="http://www.w3.org/2000/svg">
<attach/>
<attach useMode="allowForeignNS"/>
</namespace>
<namespace ns="http://www.w3.org/1999/xhtml">
<attach/>
Expand All @@ -67,4 +67,24 @@
</namespace>
</mode>

<mode name="allowForeignNS">
<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>
<anyNamespace match="elements attributes">
<allow/>
</anyNamespace>
</mode>
</rules>

0 comments on commit e3ffc37

Please sign in to comment.