Skip to content

Commit f20993e

Browse files
committed
feat: check that non-linear content is reachable
EPUB 3.3 says: > EPUB creators MUST provide a means of accessing all non-linear content > (e.g., hyperlinks in the content or from the EPUB navigation document). This commit adds a check for the above statement. - new error `OPF-096` is reported when no hyperlink was found to non-linear content in an EPUB with no script - new usage `OPF-096b` is reported when no hyperlink was found to non-linear content in a scripted EPUB (a link may be added via scripting, so we cannot report this as an error) Fix #1451
1 parent 0175818 commit f20993e

File tree

54 files changed

+402
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+402
-22
lines changed

src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ private void initialize()
289289
severities.put(MessageId.OPF_093, Severity.ERROR);
290290
severities.put(MessageId.OPF_094, Severity.ERROR);
291291
severities.put(MessageId.OPF_095, Severity.ERROR);
292+
severities.put(MessageId.OPF_096, Severity.ERROR);
293+
severities.put(MessageId.OPF_096b, Severity.USAGE);
292294

293295
// PKG
294296
severities.put(MessageId.PKG_001, Severity.WARNING);

src/main/java/com/adobe/epubcheck/messages/MessageId.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ public enum MessageId implements Comparable<MessageId>
283283
OPF_093("OPF-093"),
284284
OPF_094("OPF-094"),
285285
OPF_095("OPF-095"),
286+
OPF_096("OPF-096"),
287+
OPF_096b("OPF-096b"),
286288

287289
// Messages relating to the entire package
288290
PKG_001("PKG-001"),

src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.Set;
2626

27+
import org.w3c.epubcheck.core.references.Reference;
2728
import org.w3c.epubcheck.util.url.URLFragment;
2829

2930
import com.adobe.epubcheck.api.EPUBLocation;
@@ -183,6 +184,26 @@ else if (!overlayTextChecker.isCorrectOverlay(docURL, mo))
183184
}
184185
}
185186
}
187+
188+
// check that non-linear content documents are reachable
189+
if (item.isInSpine() && !item.isLinear() && context.referenceRegistry.isPresent()
190+
// search the reference registry for any hyperlink pointing to this item
191+
&& !context.referenceRegistry.get().asList().stream()
192+
.anyMatch(ref -> ref.type == Reference.Type.HYPERLINK
193+
&& ref.targetResource.equals(item.getURL())))
194+
{
195+
// if content is scripted, references can be added by scripting
196+
// se we only report a usage
197+
if (context.featureReport.hasFeature(FeatureEnum.HAS_SCRIPTS))
198+
{
199+
report.message(MessageId.OPF_096b, item.getLocation(), item.getPath());
200+
}
201+
// else, report an error if no hyperlink were found
202+
else
203+
{
204+
report.message(MessageId.OPF_096, item.getLocation(), item.getPath());
205+
}
206+
}
186207
}
187208

188209
@Override
@@ -194,14 +215,15 @@ protected void checkSpineItem(OPFItem item, OPFHandler opfHandler)
194215
return;
195216
}
196217

197-
String mimeType = item.getMimeType();
198-
218+
// check properties
199219
if (item.getProperties()
200220
.contains(PackageVocabs.ITEM_VOCAB.get(PackageVocabs.ITEM_PROPERTIES.DATA_NAV)))
201221
{
202222
report.message(MessageId.OPF_077, item.getLocation());
203223
}
204224

225+
// check that spine items have content document fallback
226+
String mimeType = item.getMimeType();
205227
if (!isBlessedItemType(mimeType, version))
206228
{
207229
if (!item.hasFallback())
@@ -213,7 +235,6 @@ else if (!item.hasContentDocumentFallback())
213235
report.message(MessageId.OPF_044, item.getLocation(), mimeType);
214236
}
215237
}
216-
217238
}
218239

219240
private void checkCollections()

src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ OPF_091=The item href URL must not have a fragment identifier.
210210
OPF_092=Language tag "%1$s" is not well-formed: %2$s
211211
OPF_093=The "media-type" attribute is required for linked resources located in the EPUB container
212212
OPF_094=The "media-type" attribute is required for "%1$s" links.
213-
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".
213+
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".
214+
OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s".
215+
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
214216

215217
#Package
216218
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.

src/test/resources/epub-edupub/edupub-publication.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Feature: EPUB for Education ▸ Full Publication Checks
5151

5252
## 4.2 Sectioning
5353

54-
Scenario: Verify an non-linear content does not have to follow the sectioning rules
54+
Scenario: Verify that non-linear content does not have to follow the sectioning rules
5555
When checking EPUB 'edupub-non-linear-valid'
5656
Then no errors or warnings are reported
5757

src/test/resources/epub-edupub/files/epub/edupub-non-linear-valid/EPUB/nav.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<nav epub:type="toc">
99
<ol>
1010
<li><a href="content_001.xhtml">content 001</a></li>
11+
<li><a href="nonlinear.xhtml">non-linear</a></li>
1112
</ol>
1213
</nav>
1314
</body>

src/test/resources/epub-edupub/files/epub/edupub-non-linear-valid/EPUB/package.opf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<manifest>
1212
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
1313
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
14-
<item id="non" href="nonlinear.xhtml" media-type="application/xhtml+xml" />
14+
<item id="nonlinear" href="nonlinear.xhtml" media-type="application/xhtml+xml" />
1515
</manifest>
1616
<spine>
1717
<itemref idref="content_001" />
18-
<itemref idref="non" linear="no" />
18+
<itemref idref="nonlinear" linear="no" />
1919
</spine>
2020
</package>

src/test/resources/epub-region-nav/files/epub/data-nav-in-spine-warning/EPUB/nav.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<nav epub:type="toc">
99
<ol>
1010
<li><a href="content_001.xhtml">content 001</a></li>
11+
<li><a href="data-nav.xhtml">data nav</a></li>
1112
</ol>
1213
</nav>
1314
</body>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
</metadata>
9+
<manifest>
10+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
</manifest>
13+
<spine>
14+
<!-- <itemref idref="content_001" />-->
15+
</spine>
16+
</package>

0 commit comments

Comments
 (0)