Skip to content

Commit

Permalink
fixes nav doc validation to be more faithful to the spec:
Browse files Browse the repository at this point in the history
- only restrict a nav element's content model when it carries an epub:type attribute
- require a first-child heading for all nav elements not defined in the spec (including without an epub:type)
- require at least one li child for ol (also fixes existing errors in test docs)
- add warning that nav elements should have an epub:type attribute
  • Loading branch information
mattgarrish authored and rdeltour committed Jun 6, 2017
1 parent 275f6b6 commit d32de85
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
23 changes: 17 additions & 6 deletions src/main/resources/com/adobe/epubcheck/schema/30/epub-nav-30.rnc
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@



default namespace = "http://www.w3.org/1999/xhtml"
namespace epub = "http://www.idpf.org/2007/ops"

include "epub-xhtml-30.rnc" {
html5.nav.content = html5.headings.class?, html5.ol
html5.oli.content = html5.a.phrasing | ((html5.a.phrasing | html5.span), html5.ol)
html5.nav.attlist &= epub.nav.attrs
}


epub.nav.attrs &= html5.global.common.attrs & epub.nav.xml.attrs
epub.nav.xml.attrs &= html5.xml.lang.attr? & html5.xml.base.attr? & html5.xml.space.attr?

html5.sections.class |= epub.nav

epub.nav = element nav { epub.type.attr & epub.nav.attrs & epub.nav.content }
epub.nav.content = html5.headings.class?, epub.nav.ol

epub.nav.ol = element ol { html5.ol.attlist & epub.nav.ol.content }
epub.nav.ol.content = epub.nav.oli+

epub.nav.oli = element li { html5.oli.attlist & epub.nav.oli.content }
epub.nav.oli.content = html5.a.phrasing | ((html5.a.phrasing | html5.span), epub.nav.ol)
20 changes: 12 additions & 8 deletions src/main/resources/com/adobe/epubcheck/schema/30/epub-nav-30.sch
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</pattern>

<pattern id="span-no-sublist">
<rule context="html:body//html:nav//html:span">
<rule context="html:body//html:nav[@epub:type]//html:span">
<assert test="count(.//ol) = 0"> The span element must only be used as heading for flat
sublists (not hierarchical navigation structures) </assert>
</rule>
Expand All @@ -30,15 +30,15 @@
</pattern>

<pattern id="link-labels">
<rule context="html:nav//html:ol//html:a">
<rule context="html:nav[@epub:type]//html:ol//html:a">
<assert
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
>Anchors within nav elements must contain text</assert>
</rule>
</pattern>

<pattern id="span-labels">
<rule context="html:nav//html:ol//html:span">
<rule context="html:nav[@epub:type]//html:ol//html:span">
<assert
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
>Spans within nav elements must contain text</assert>
Expand All @@ -48,21 +48,25 @@
<pattern id="req-heading">
<rule
context="html:nav[not(tokenize(@epub:type,'\s+') = ('toc','page-list','landmarks'))]">
<let name="fc" value="local-name(./*[1])"/>
<assert test="(starts-with($fc,'h') and string-length($fc) = 2) or ($fc = 'hgroup')">nav
elements other than 'toc', 'page-list' and 'landmarks' must contain a heading as the
<assert test="child::*[1][self::html:h1|self::html:h2|self::html:h3|self::html:h4|self::html:h5|self::html:h6]">nav
elements other than 'toc', 'page-list' and 'landmarks' must have a heading as their
first child</assert>
</rule>
</pattern>

<pattern id="heading-content">
<rule context="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:hgroup">
<rule context="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6">
<assert
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
>Heading elements must contain text</assert>
</rule>
</pattern>


<pattern id="other-nav-type">
<rule context="html:nav">
<report test="not(@epub:type)">WARNING: nav elements should have an epub:type attribute</report>
</rule>
</pattern>

<!-- warnings mode <pattern id="page-list-flat">
<rule context="html:body//html:nav[@epub:type='page-list']">
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void testValidateDocumentValidNav001()
public void testValidateDocumentNoTocNav()
{
Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005, MessageId.RSC_005);
Collections.addAll(expectedWarnings, MessageId.RSC_017);
testValidateDocument("invalid/noTocNav.xhtml");
}

Expand Down Expand Up @@ -183,6 +184,7 @@ public void testValidateDocumentNavNoToc()
public void testValidateDocumentNavReqHeading()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
Collections.addAll(expectedWarnings, MessageId.RSC_017);
testValidateDocument("invalid/req-heading.xhtml");
}

Expand Down
Binary file modified src/test/resources/30/epub/invalid/issue239.epub
Binary file not shown.
Binary file modified src/test/resources/30/epub/valid/epub30-spec.epub
Binary file not shown.
Binary file modified src/test/resources/30/epub/valid/issue262.epub
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"elapsedTime" : 85,
"nFatal" : 0,
"nError" : 1,
"nWarning" : 0,
"nWarning" : 1,
"nUsage" : 4
},
"publication" : {
Expand Down Expand Up @@ -237,5 +237,17 @@
"context" : null
} ],
"suggestion" : null
}, {
"ID" : "RSC-017",
"severity" : "WARNING",
"message" : "Warning while parsing file: nav elements should have an epub:type attribute",
"additionalLocations" : 0,
"locations" : [ {
"path" : "OPS/toc.xhtml",
"line" : 9,
"column" : 6,
"context" : null
} ],
"suggestion" : null
} ]
}

0 comments on commit d32de85

Please sign in to comment.