Skip to content

Commit 3c8dab3

Browse files
committed
fix: allow nav items containing multiple images
A bug in the Schematron XPath expressions caused a fatal error to be reported when nav doc items contained multiple images. This commit fix the relevant expressions by using the `string-join` function instead of `concat`, allowing to join arbitrary sequences of text nodes. Fix #1476
1 parent b2c5d8c commit 3c8dab3

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

src/main/resources/com/adobe/epubcheck/schema/30/edupub/edu-structure.sch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<report test="count($headings) &gt; 1">More than one ranked heading found as direct descendant of body.</report>
3737

38-
<report test="count($headings) = 1 and string-length(normalize-space(concat($headings,$headings/html:img/@alt,$headings//@aria-label))) = 0">Empty ranked heading detected.</report>
38+
<report test="count($headings) = 1 and string-length(normalize-space(string-join($headings|$headings/html:img/@alt|$headings//@aria-label))) = 0">Empty ranked heading detected.</report>
3939

4040
<report test="@aria-label and (normalize-space($headings) = normalize-space(@aria-label))">The value of the "aria-label" attribute must not be the same as the content of the heading.</report>
4141
</rule>
@@ -53,7 +53,7 @@
5353

5454
<report test="count($headings) &gt; 1">More than one ranked heading found as direct descendant of <value-of select="name()"/>.</report>
5555

56-
<report test="count($headings) = 1 and string-length(normalize-space(concat($headings,$headings/html:img/@alt,$headings//@aria-label))) = 0">Empty ranked heading detected.</report>
56+
<report test="count($headings) = 1 and string-length(normalize-space(string-join($headings|$headings/html:img/@alt|$headings//@aria-label))) = 0">Empty ranked heading detected.</report>
5757

5858
<report test="@aria-label and (normalize-space($headings) = normalize-space(@aria-label))">The value of the "aria-label" attribute must not be the same as the content of the heading.</report>
5959
</rule>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
<pattern id="link-labels">
4848
<rule context="html:nav[@epub:type]//html:ol//html:a">
4949
<assert
50-
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
50+
test="string-length(normalize-space(string-join(.|./html:img/@alt|.//@aria-label))) > 0"
5151
>Anchors within nav elements must contain text</assert>
5252
</rule>
5353
</pattern>
5454

5555
<pattern id="span-labels">
5656
<rule context="html:nav[@epub:type]//html:ol//html:span">
5757
<assert
58-
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
58+
test="string-length(normalize-space(string-join(.|./html:img/@alt|.//@aria-label))) > 0"
5959
>Spans within nav elements must contain text</assert>
6060
</rule>
6161
</pattern>
@@ -72,7 +72,7 @@
7272
<pattern id="heading-content">
7373
<rule context="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6">
7474
<assert
75-
test="string-length(normalize-space(concat(.,./html:img/@alt,.//@aria-label))) > 0"
75+
test="string-length(normalize-space(string-join(.|./html:img/@alt|.//@aria-label))) > 0"
7676
>Heading elements must contain text</assert>
7777
</rule>
7878
</pattern>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml"><img src="decorative.jpg" alt="" /><img src="textual.jpg" alt="some text" /></a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
3+
lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Minimal Nav</title>
7+
</head>
8+
<body>
9+
<nav epub:type="toc">
10+
<ol>
11+
<li>
12+
<span><img src="decorative.jpg" alt="" /><img src="textual.jpg" alt="some text" /></span>
13+
<ol>
14+
<li><a href="content_001.xhtml">content 001</a></li>
15+
</ol>
16+
</li>
17+
</ol>
18+
</nav>
19+
</body>
20+
</html>

src/test/resources/epub3/07-navigation-document/navigation-document.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Feature: EPUB 3 — Navigation Document
6363
Then error RSC-005 is reported
6464
And the message contains 'Spans within nav elements must contain text'
6565
And no other errors or warnings are reported
66+
67+
Scenario: Allow multiple images in a list item label
68+
Given EPUBCheck configured to check a navigation document
69+
When checking document 'content-model-li-label-multiple-images-valid.xhtml'
70+
Then no errors or warnings are reported
6671

6772
@spec @xref:sec-nav-def-model
6873
Scenario: Report a leaf list item with no link (just a span label)
@@ -79,6 +84,11 @@ Feature: EPUB 3 — Navigation Document
7984
Then error RSC-005 is reported
8085
And the message contains 'Anchors within nav elements must contain text'
8186
And no other errors or warnings are reported
87+
88+
Scenario: Allow multiple images in a nav hyperlink
89+
Given EPUBCheck configured to check a navigation document
90+
When checking document 'content-model-a-multiple-images-valid.xhtml'
91+
Then no errors or warnings are reported
8292

8393
@spec @xref:sec-nav-def-model
8494
Scenario: Report a nav hyperlink without content (but an empty nested span)

0 commit comments

Comments
 (0)