Skip to content

Commit

Permalink
issue a warning when landmarks anchors are not unique // refs #493
Browse files Browse the repository at this point in the history
  • Loading branch information
tofi86 committed Aug 15, 2017
1 parent 25f28c0 commit 557308e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
17 changes: 15 additions & 2 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 @@ -24,8 +24,21 @@

<pattern id="landmarks">
<rule context="html:nav[tokenize(@epub:type,'\s+')='landmarks']//html:ol//html:a">
<assert test="@epub:type">Missing epub:type attribute on anchor inside 'landmarks' nav
element</assert>
<let name="current_type_normalized" value="normalize-space(lower-case(@epub:type))"/>
<let name="current_href_normalized" value="normalize-space(lower-case(@html:href))"/>

<!-- Check for missing epub:type attributes -->
<assert test="@epub:type">Missing epub:type attribute on anchor inside 'landmarks' nav element</assert>

<!--
landmarks anchors should be unique (#493)
and only reported within the same ancestor landmarks element
-->
<assert test="
count(ancestor::html:nav[tokenize(@epub:type,'\s+')='landmarks']//html:ol//html:a[
normalize-space(lower-case(@epub:type)) = $current_type_normalized and
normalize-space(lower-case(@html:href)) = $current_href_normalized
]) = 1">WARNING: Duplicate 'a' elements with the same 'epub:type' and 'href' attributes inside 'landmarks' nav element</assert>
</rule>
</pattern>

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public void testValidateDocumentNavLandmarks002()
testValidateDocument("invalid/nav-landmarks-002.xhtml");
}

@Test
public void testValidateDocumentNavLandmarksDuplicates()
{
// Multiple occurrences of the 'landmarks' nav element
Collections.addAll(expectedWarnings, MessageId.RSC_017, MessageId.RSC_017);
testValidateDocument("invalid/nav-landmarks-duplicates.xhtml");
}

@Test
public void testValidateDocumentNavNoPagelist001()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen RNGSchema="../../../src/schema/epub-nav-30.rnc" type="compact"?>
<?oxygen SCHSchema="../../../src/schema/epub-xhtml-30.sch"?>
<?oxygen SCHSchema="../../../src/schema/epub-nav-30.sch"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head></head>
<body>

<nav epub:type="toc" id="toc">
<!-- the navMap -->
<h1>Table of contents</h1>
<ol>
<li><a href="chap1.xhtml">Chapter 1</a>
<ol>
<li><a href="chap1.1.xhtml">arbitrary XHTML Phrasing content</a></li>
<li><a href="chap1.2.xhtml">arbitrary XHTML Phrasing content</a></li>
</ol>
</li>
<li><a href="chap1.xhtml">Chapter 2</a></li>
</ol>
</nav>

<nav epub:type="landmarks">
<!-- the guide -->
<h2>Guide</h2>
<ol>
<li><a epub:type="toc" href="#toc">Table of Contents</a></li>
<li><a epub:type="loi" href="content.html#loi">List of Illustrations</a></li>
<li><a epub:type="bodymatter" href="content.html#bodymatter">Start of Content</a></li>
<li><a epub:type="loi" href="content.html#loi">List of Illustrations</a></li>
</ol>
</nav>

</body>
</html>

0 comments on commit 557308e

Please sign in to comment.