Skip to content

Commit

Permalink
fix: page break role / page list errors were reported multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
danielweck committed Feb 8, 2025
1 parent fdcb568 commit ea6171a
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function checkReadingOrder(epub) {
// let pos = -1;
let failed = undefined;
for (const page of pageListFilePathsAndTargetIDs) {
failed = undefined;
const found = docs.findIndex((doc) => page.full === doc.full);
if (found === -1) {
failed = page;
Expand Down Expand Up @@ -418,7 +419,7 @@ function checkReadingOrder(epub) {
kbTitle: localize("checkepub.pagelistbrokenviolation.kbtitle"),
ruleDesc: localize("checkepub.pagelistbrokenviolation.ruledesc", { ref, interpolation: { escapeValue: false } })
}));
// break;
// break; MAKE SURE failed IS RESET TO undefined at each loop iteration
}
}
if (!isFXL) {
Expand Down Expand Up @@ -460,6 +461,7 @@ function checkReadingOrder(epub) {
let pos = -1;
let failed = undefined;
for (const toc of tocFilePathsAndTargetIDs) {
failed = undefined;
const found = docs.findIndex((doc) => toc.full === doc.full);
if (found === -1) {
failed = toc;
Expand All @@ -483,7 +485,7 @@ function checkReadingOrder(epub) {
kbTitle: localize("checkepub.ordertocviolation.kbtitle"),
ruleDesc: localize("checkepub.ordertocviolation.ruledesc", { ref, interpolation: { escapeValue: false } })
}));
break;
break; // NO NEED TO MAKE SURE failed IS RESET TO undefined at each loop iteration
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/__tests__/epub-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ test('nothing to report', async () => {
});

describe('page list and TOC reading order', () => {

test('minor missing page break for a page list item', async () => {
const report = await ace('../data/epubrules-pagelist-missing-pagebreak-target');
// console.log(JSON.stringify(report, null, 4));
expect(report['earl:result']['earl:outcome']).toEqual('fail');
const assertions = findAssertionsForDoc(report, '/EPUB/nav.xhtml');
// console.log(JSON.stringify(assertions, null, 4));
expect(assertions).toEqual(expect.arrayContaining([

expect.objectContaining({
'earl:test': expect.objectContaining({
'dct:title': 'epub-pagelist-broken',
"earl:impact": "minor",
"dct:description": expect.stringMatching(/.+content_001\.xhtml#p1.+/),
}),
}),

]));
});

test('TOC correctly ordered PASS but missing page list item for a page break', async () => {
const report = await ace('../data/epubrules-pagelist-missing-pagebreak');
// console.log(JSON.stringify(report, null, 4));
Expand All @@ -67,6 +87,13 @@ describe('page list and TOC reading order', () => {
"dct:description": expect.stringMatching(/.+content_002\.xhtml#p3.+/),
}),
}),
expect.objectContaining({
'earl:test': expect.objectContaining({
'dct:title': 'epub-pagelist-missing-pagebreak',
"earl:impact": "serious",
"dct:description": expect.stringMatching(/.+content_002\.xhtml#p5.+/),
}),
}),
]));
});
test('page list and TOC correctly ordered PASS, but SMIL missing pagebreak epub:type', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB 1</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<span id="p1" epub:typexx="pagebreak" rolexx="doc-pagebreak" aria-label="p1"/>
<section id="sec"><p>txt1</p><p id="useless">txt2
<span id="p2" epub:type="pagebreak" role="doc-pagebreak" aria-label="p2">p2</span>
txt3</p><p>txt4</p></section>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB 2</title>
</head>
<body>
<h1>Other</h1>
<p>Bla.</p>
<section id="sec"><p>txt1</p><p id="useless">txt2
<span id="p3" epub:type="pagebreak" role="doc-pagebreak" aria-label="p3">p3</span>
txt3</p><p>txt4</p></section>
<span id="p4" epub:type="pagebreak" role="doc-pagebreak" aria-label="p4"/>

<span id="p5" epub:type="pagebreak" role="doc-pagebreak" aria-label="p5"> MISSING p5 in pagelist</span>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>

<a href="dummyHREF1">DUMMY 1</a>

<nav epub:type="toc" role="doc-toc">
<ol>
<li><a href="./content_001.xhtml">content 001</a></li>
<li><ol>
<li><a href="content_001.xhtml#p1">page 1</a></li>
<li><a href="content_001.xhtml#sec">section</a></li>
<li><a href="content_001.xhtml#p2">page 2</a></li>
</ol>
</li>
<li><a href="../EPUB/content_002.xhtml">content 002</a></li>
<li><ol>
<li><a href="content_002.xhtml#sec">section</a></li>
<li><a href="../EPUB/./content_002.xhtml#p3">page 3</a></li>
<li><a href="content_002.xhtml#p4">page 4</a></li>
</ol>
</li>
</ol>
</nav>
<nav epub:type="page-list" role="doc-pagelist">
<ol>
<li><a href="content_001.xhtml#p1">p1</a></li>
<li><a href="content_001.xhtml#p2">p2</a></li>
<li><a href="content_002.xhtml#p3">p3</a></li>
<li><a href="content_002.xhtml#p4">p4</a></li>
<li><a href="content_002.xhtml#p5">p5</a></li>
</ol>
</nav>

<a href="dummyHREF2">DUMMY2</a>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>

<dc:source id="pg-src">urn:isbn:9781234567891</dc:source>
<meta property="source-of" refines="#pg-src">pagination</meta>
<!-- meta property="pageBreakSource">urn:isbn:9781234567891</meta -->

<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="content_002" href="content_002.xhtml" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="content_001" />
<itemref idref="content_002" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
txt3</p><p>txt4</p></section>
<span id="p4" epub:type="pagebreak" role="doc-pagebreak" aria-label="p4"/>

<span id="p5" role="doc-pagebreak" aria-label="p5">NOT MISSING p5 in pagelist</span>
<span id="p5" role="doc-pagebreak" aria-label="p5"> MISSING p5 in pagelist</span>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<!-- li><a href="content_001.xhtml#p2">p2</a></li -->
<!-- li><a href="content_002.xhtml#p3">p3</a></li -->
<li><a href="content_002.xhtml#p4">p4</a></li>
<!-- li><a href="content_002.xhtml#p5">p5</a></li -->
</ol>
</nav>

Expand Down

0 comments on commit ea6171a

Please sign in to comment.