Skip to content

Commit 557308e

Browse files
committed
issue a warning when landmarks anchors are not unique // refs #493
1 parent 25f28c0 commit 557308e

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/main/resources/com/adobe/epubcheck/schema/30/epub-nav-30.sch

+15-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@
2424

2525
<pattern id="landmarks">
2626
<rule context="html:nav[tokenize(@epub:type,'\s+')='landmarks']//html:ol//html:a">
27-
<assert test="@epub:type">Missing epub:type attribute on anchor inside 'landmarks' nav
28-
element</assert>
27+
<let name="current_type_normalized" value="normalize-space(lower-case(@epub:type))"/>
28+
<let name="current_href_normalized" value="normalize-space(lower-case(@html:href))"/>
29+
30+
<!-- Check for missing epub:type attributes -->
31+
<assert test="@epub:type">Missing epub:type attribute on anchor inside 'landmarks' nav element</assert>
32+
33+
<!--
34+
landmarks anchors should be unique (#493)
35+
and only reported within the same ancestor landmarks element
36+
-->
37+
<assert test="
38+
count(ancestor::html:nav[tokenize(@epub:type,'\s+')='landmarks']//html:ol//html:a[
39+
normalize-space(lower-case(@epub:type)) = $current_type_normalized and
40+
normalize-space(lower-case(@html:href)) = $current_href_normalized
41+
]) = 1">WARNING: Duplicate 'a' elements with the same 'epub:type' and 'href' attributes inside 'landmarks' nav element</assert>
2942
</rule>
3043
</pattern>
3144

src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ public void testValidateDocumentNavLandmarks002()
172172
testValidateDocument("invalid/nav-landmarks-002.xhtml");
173173
}
174174

175+
@Test
176+
public void testValidateDocumentNavLandmarksDuplicates()
177+
{
178+
// Multiple occurrences of the 'landmarks' nav element
179+
Collections.addAll(expectedWarnings, MessageId.RSC_017, MessageId.RSC_017);
180+
testValidateDocument("invalid/nav-landmarks-duplicates.xhtml");
181+
}
182+
175183
@Test
176184
public void testValidateDocumentNavNoPagelist001()
177185
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?oxygen RNGSchema="../../../src/schema/epub-nav-30.rnc" type="compact"?>
3+
<?oxygen SCHSchema="../../../src/schema/epub-xhtml-30.sch"?>
4+
<?oxygen SCHSchema="../../../src/schema/epub-nav-30.sch"?>
5+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
6+
<head></head>
7+
<body>
8+
9+
<nav epub:type="toc" id="toc">
10+
<!-- the navMap -->
11+
<h1>Table of contents</h1>
12+
<ol>
13+
<li><a href="chap1.xhtml">Chapter 1</a>
14+
<ol>
15+
<li><a href="chap1.1.xhtml">arbitrary XHTML Phrasing content</a></li>
16+
<li><a href="chap1.2.xhtml">arbitrary XHTML Phrasing content</a></li>
17+
</ol>
18+
</li>
19+
<li><a href="chap1.xhtml">Chapter 2</a></li>
20+
</ol>
21+
</nav>
22+
23+
<nav epub:type="landmarks">
24+
<!-- the guide -->
25+
<h2>Guide</h2>
26+
<ol>
27+
<li><a epub:type="toc" href="#toc">Table of Contents</a></li>
28+
<li><a epub:type="loi" href="content.html#loi">List of Illustrations</a></li>
29+
<li><a epub:type="bodymatter" href="content.html#bodymatter">Start of Content</a></li>
30+
<li><a epub:type="loi" href="content.html#loi">List of Illustrations</a></li>
31+
</ol>
32+
</nav>
33+
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)