Skip to content

Commit

Permalink
fix: metadata accessibility feature printPageNumbers/pageBreakMarkers…
Browse files Browse the repository at this point in the history
… (missing page breaks in publication content documents) VERSUS pageNavigation (missing navigation document page list)
  • Loading branch information
danielweck committed Dec 1, 2024
1 parent 10d549c commit bd1d9d1
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 42 deletions.
43 changes: 28 additions & 15 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function newMetadataAssertion(name, impact = 'serious') {
// "Value '{{value}}' is invalid for '{{name}}' metadata"

function checkMetadata(assertions, epub) {
let has_accessibilityFeature_printPageNumbersPageBreakMarkers = false;

// Check metadata values
for (const name in a11yMetadata.A11Y_META) {
const meta = a11yMetadata.A11Y_META[name];
Expand Down Expand Up @@ -198,12 +200,18 @@ function checkMetadata(assertions, epub) {
}))
});
}

// Check consistency of the printPageNumbers feature
if (name === 'schema:accessibilityFeature'
&& (splitValues.includes('printPageNumbers') || splitValues.includes('pageBreakMarkers'))
&& !epub.navDoc.hasPageList) {

const has_accessibilityFeature_pageNavigation =
name === 'schema:accessibilityFeature'
&& splitValues.includes('pageNavigation');

has_accessibilityFeature_printPageNumbersPageBreakMarkers = has_accessibilityFeature_printPageNumbersPageBreakMarkers ||
name === 'schema:accessibilityFeature' && (splitValues.includes('printPageNumbers') || splitValues.includes('pageBreakMarkers'));

if (has_accessibilityFeature_pageNavigation && !epub.navDoc.hasPageList
// || !has_accessibilityFeature_pageNavigation && epub.navDoc.hasPageList
) {
assertions.withAssertions(newViolation({
impact: 'moderate',
title: `metadata-accessibilityFeature-printPageNumbers-nopagelist`,
Expand All @@ -212,12 +220,13 @@ function checkMetadata(assertions, epub) {
kbPath: 'docs/metadata/schema.org/index.html',
kbTitle: localize("checkepub.metadataprintpagenumbers.kbtitle"),
ruleDesc: localize("checkepub.metadataprintpagenumbers.ruledesc", {})
}))
}));
}
});
}
}
}
return has_accessibilityFeature_printPageNumbersPageBreakMarkers;
}

function checkMediaOverlays(epub) {
Expand Down Expand Up @@ -327,7 +336,7 @@ function checkReadingOrder(epub) {
.withTestSubject(resPath, "");

// console.log("EPUB", JSON.stringify(epub, null, 4));

const docs = [];
for (const doc of epub.contentDocs) {
if (doc.notInReadingOrder) { // NavDoc artificially appended
Expand Down Expand Up @@ -532,7 +541,7 @@ function check(epub, report) {
const assertionsMO = checkMediaOverlays(epub);

// Check a11y metadata
checkMetadata(assertion, epub);
const has_accessibilityFeature_printPageNumbersPageBreakMarkers = checkMetadata(assertion, epub);

// Check presence of a title
checkTitle(assertion, epub);
Expand All @@ -552,8 +561,8 @@ function check(epub, report) {
}
}

const builtAssertions = assertion.build();
report.addAssertions(builtAssertions);
// const builtAssertions = assertion.build();
// report.addAssertions(builtAssertions);

// Report the Nav Doc
report.addEPUBNav(epub.navDoc);
Expand All @@ -565,12 +574,16 @@ function check(epub, report) {
hasSVGContentDocuments: epub.hasSVGContentDocuments,
});

winston.info(`- ${epub.packageDoc.src}: ${
(builtAssertions.assertions && builtAssertions.assertions.length > 0)
? builtAssertions.assertions.length
: 'No'} issues found`);
// winston.info(`- ${epub.packageDoc.src}: ${
// (builtAssertions.assertions && builtAssertions.assertions.length > 0)
// ? builtAssertions.assertions.length
// : 'No'} issues found`);

return Promise.resolve();
return Promise.resolve({
assertion,
has_accessibilityFeature_printPageNumbersPageBreakMarkers,
});
}

module.exports.check = check;
module.exports.newViolation = newViolation;
45 changes: 43 additions & 2 deletions packages/ace-core/src/checker/checker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { localize } = require('../l10n/localize').localizer;
const htmlChecker = require('./checker-chromium.js');
const epubChecker = require('./checker-epub.js');
const winston = require('winston');
Expand Down Expand Up @@ -43,6 +44,46 @@ function consolidate(results, report) {

module.exports.check = function check(epub, report, lang, axeRunner) {
return epubChecker.check(epub, report)
.then(() => htmlChecker.check(epub, lang, axeRunner))
.then(results => consolidate(results, report));
.then(async (obj) => {
return htmlChecker.check(epub, lang, axeRunner).then((results) => {
return new Promise((res) => {
res({
assertion: obj.assertion,
has_accessibilityFeature_printPageNumbersPageBreakMarkers: obj.has_accessibilityFeature_printPageNumbersPageBreakMarkers,
res: results,
});
});
});
})
.then((results) => {
// console.log(JSON.stringify(results, null, 4));
// throw new Error("DEBUGG");

const hasPageBreaks = !!results.res.find((item) => {
return !!item.properties.hasPageBreaks;
});
if (results.has_accessibilityFeature_printPageNumbersPageBreakMarkers && !hasPageBreaks
// || !results.has_accessibilityFeature_printPageNumbersPageBreakMarkers && hasPageBreaks
) {
results.assertion.withAssertions(epubChecker.newViolation({
impact: 'moderate',
title: `metadata-accessibilityFeature-printPageNumbers-nopagebreaks`,
testDesc: localize("checkepub.metadatapagebreaks.testdesc", {}),
resDesc: localize("checkepub.metadatapagebreaks.resdesc", {}),
kbPath: 'docs/metadata/schema.org/index.html',
kbTitle: localize("checkepub.metadatapagebreaks.kbtitle"),
ruleDesc: localize("checkepub.metadatapagebreaks.ruledesc", {})
}));
}

const builtAssertions = results.assertion.build();
report.addAssertions(builtAssertions);

winston.info(`- ${epub.packageDoc.src}: ${
(builtAssertions.assertions && builtAssertions.assertions.length > 0)
? builtAssertions.assertions.length
: 'No'} issues found`);

return consolidate(results.res, report);
});
};
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Metadata for tilgængelighed fra Schema.org",
"resdesc": "Tilføj en liste over sider til navigations-dokumentet",
"ruledesc": "Når tilgængeligheds-egenskaben 'printPageNumbers'/'pageBreakMarkers' bruges, bør navigations-dokumentet indeholde en liste over sider",
"testdesc": "Tilgængeligheds-egenskaben 'printPageNumbers'/'pageBreakMarkers' bruges, men ingen liste over sider er angivet"
"ruledesc": "Når tilgængeligheds-egenskaben 'pageNavigation' bruges, bør navigations-dokumentet indeholde en liste over sider",
"testdesc": "Tilgængeligheds-egenskaben 'pageNavigation' bruges, men ingen liste over sider er angivet"
},
"metadataviolation": {
"kbtitle": "Metadata for tilgængelighed fra Schema.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Schema.org Barrierefreiheitsmetadaten",
"resdesc": "Eine Seitenübersicht zum Navigationsdokument hinzufügen",
"ruledesc": "Wenn die Barrierefreiheitsfunktion 'printPageNumbers'/'pageBreakMarkers' angegeben ist, sollte das Navigationsdokument eine Seitenübersicht enthalten",
"testdesc": "Barrierefreiheitsfunktion 'printPageNumbers'/'pageBreakMarkers' ist angegeben aber die Seitenübersicht fehlt"
"ruledesc": "Wenn die Barrierefreiheitsfunktion 'pageNavigation' angegeben ist, sollte das Navigationsdokument eine Seitenübersicht enthalten",
"testdesc": "Barrierefreiheitsfunktion 'pageNavigation' ist angegeben aber die Seitenübersicht fehlt"
},
"metadataviolation": {
"kbtitle": "Schema.org Barrierefreiheitsmetadaten",
Expand Down
10 changes: 8 additions & 2 deletions packages/ace-core/src/l10n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
"ruledesc": "'{{name}}' metadata must be set to one of the expected values",
"testdesc": "Value '{{value}}' is invalid for '{{name}}' metadata"
},
"metadatapagebreaks": {
"kbtitle": "Schema.org Accessibility Metadata",
"resdesc": "Add page breaks to publication documents",
"ruledesc": "When the accessibility feature 'printPageNumbers'/'pageBreakMarkers' is declared, documents should include page breaks",
"testdesc": "Accessibility feature 'printPageNumbers'/'pageBreakMarkers' is declared but there are no page breaks"
},
"metadataprintpagenumbers": {
"kbtitle": "Schema.org Accessibility Metadata",
"resdesc": "Add a page list to the Navigation Document",
"ruledesc": "When the accessibility feature 'printPageNumbers'/'pageBreakMarkers' is declared, the Navigation Document should include a page list",
"testdesc": "Accessibility feature 'printPageNumbers'/'pageBreakMarkers' is declared but page list is missing"
"ruledesc": "When the accessibility feature 'pageNavigation' is declared, the Navigation Document should include a page list",
"testdesc": "Accessibility feature 'pageNavigation' is declared but page list is missing"
},
"metadataviolation": {
"kbtitle": "Schema.org Accessibility Metadata",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Metadatos de Accesibilidad Schema.org",
"resdesc": "Añadir una lista de páginas al documento de navegación",
"ruledesc": "Cuando se haya declarado la función de accesibilidad 'printPageNumbers'/'pageBreakMarkers', el documento de navegación debería incluir una lista de páginas",
"testdesc": "La función de accesibilidad 'printPageNumbers'/'pageBreakMarkers' se ha declarado, pero la lista de páginas está ausente"
"ruledesc": "Cuando se haya declarado la función de accesibilidad 'pageNavigation', el documento de navegación debería incluir una lista de páginas",
"testdesc": "La función de accesibilidad 'pageNavigation' se ha declarado, pero la lista de páginas está ausente"
},
"metadataviolation": {
"kbtitle": "Metadatos de Accesibilidad Schema.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Schema.org Accessibility Metadata",
"resdesc": "Ajouter une liste de pages au document de navigation",
"ruledesc": "Quand la propriété d’accessibilité 'printPageNumbers'/'pageBreakMarkers' est déclarée, le document de navigation doit avoir une liste de pages",
"testdesc": "La propriété d’accessibilité 'printPageNumbers'/'pageBreakMarkers' est déclarée mais aucune liste de pages n’a été trouvée"
"ruledesc": "Quand la propriété d’accessibilité 'pageNavigation' est déclarée, le document de navigation doit avoir une liste de pages",
"testdesc": "La propriété d’accessibilité 'pageNavigation' est déclarée mais aucune liste de pages n’a été trouvée"
},
"metadataviolation": {
"kbtitle": "Métadonnées d'accessibilité Schema.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Schema.orgアクセシビリティメタデータ",
"resdesc": "ナビゲーションドキュメントにページリストを追加する",
"ruledesc": "アクセシビリティ機能「printPageNumbers」/「pageBreakMarkers」が宣言されている場合、ナビゲーションドキュメントにページリストを含める必要があります",
"testdesc": "アクセシビリティ機能「printPageNumbers」/「pageBreakMarkers」は宣言されていますが、ページリストがありません"
"ruledesc": "アクセシビリティ機能「pageNavigation」が宣言されている場合、ナビゲーションドキュメントにページリストを含める必要があります",
"testdesc": "アクセシビリティ機能「pageNavigation」は宣言されていますが、ページリストがありません"
},
"metadataviolation": {
"kbtitle": "Schema.orgアクセシビリティメタデータ",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Metadados de Acessibilidade Schema.org",
"resdesc": "Adicione uma lista de páginas ao Documento de Navegação",
"ruledesc": "Quando o recurso de acessibilidade 'printPageNumbers'/'pageBreakMarkers' é declarado, o Documento de Navegação deve incluir uma lista de páginas",
"testdesc": "O recurso de acessibilidade 'printPageNumbers'/'pageBreakMarkers' foi declarado mas a lista de páginas está ausente"
"ruledesc": "Quando o recurso de acessibilidade 'pageNavigation' é declarado, o Documento de Navegação deve incluir uma lista de páginas",
"testdesc": "O recurso de acessibilidade 'pageNavigation' foi declarado mas a lista de páginas está ausente"
},
"metadataviolation": {
"kbtitle": "Metadados de Acessibilidade Schema.org",
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/l10n/locales/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"metadataprintpagenumbers": {
"kbtitle": "Schema.org可及性詮釋資料",
"resdesc": "在導覽文件中加入頁面列表",
"ruledesc": "當宣告可及性功能「printPageNumbers」/「pageBreakMarkers」時,導覽文件中應該包含一份頁面列表",
"testdesc": "可及性功能中宣告了「printPageNumbers」/「pageBreakMarkers」,但未包含頁面列表"
"ruledesc": "當宣告可及性功能「pageNavigation」時,導覽文件中應該包含一份頁面列表",
"testdesc": "可及性功能中宣告了「pageNavigation」,但未包含頁面列表"
},
"metadataviolation": {
"kbtitle": "Schema.org可及性詮釋資料",
Expand Down
25 changes: 21 additions & 4 deletions tests/__tests__/epub-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ describe('accessibility metadata', () => {
}),
]));
});
test('`printPageNumbers` is declared as a feature but the Nav Doc has no page list', async () => {
const report = await ace('../data/epubrules-metadata-printPageNumbers-nopagelist');

test('`pageNavigation` is declared as a feature but the Nav Doc has no page list', async () => {
const report = await ace('../data/epubrules-metadata-pageNavigation-nopagelist');
// console.log(JSON.stringify(report, null, 4));
expect(report['earl:result']['earl:outcome']).toEqual('fail');
const assertions = findAssertionsForDoc(report, 'EPUB/package.opf');
expect(assertions).toEqual(expect.arrayContaining([
Expand All @@ -432,14 +434,29 @@ describe('accessibility metadata', () => {
}),
]));
});
test('`pageBreakMarkers` is declared as a feature but the Nav Doc has no page list', async () => {

test('`printPageNumbers` is declared as a feature but the publication content has no page breaks', async () => {
const report = await ace('../data/epubrules-metadata-printPageNumbers-nopagelist');
// console.log(JSON.stringify(report, null, 4));
expect(report['earl:result']['earl:outcome']).toEqual('fail');
const assertions = findAssertionsForDoc(report, 'EPUB/package.opf');
expect(assertions).toEqual(expect.arrayContaining([
expect.objectContaining({
'earl:test': expect.objectContaining({
'dct:title': 'metadata-accessibilityFeature-printPageNumbers-nopagebreaks',
}),
}),
]));
});
test('`pageBreakMarkers` is declared as a feature but the publication content has no page breaks', async () => {
const report = await ace('../data/epubrules-metadata-pageBreakMarkers-nopagelist');
// console.log(JSON.stringify(report, null, 4));
expect(report['earl:result']['earl:outcome']).toEqual('fail');
const assertions = findAssertionsForDoc(report, 'EPUB/package.opf');
expect(assertions).toEqual(expect.arrayContaining([
expect.objectContaining({
'earl:test': expect.objectContaining({
'dct:title': 'metadata-accessibilityFeature-printPageNumbers-nopagelist',
'dct:title': 'metadata-accessibilityFeature-printPageNumbers-nopagebreaks',
}),
}),
]));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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>
<nav epub:type="toc" role="doc-toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilityFeature">pageNavigation</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"/>
</manifest>
<spine>
<itemref idref="content_001" />
</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 @@ -4,7 +4,7 @@
<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 -->
Expand Down
2 changes: 1 addition & 1 deletion tests/data/issue-85/EPUB/package.opf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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 -->
Expand Down
Loading

0 comments on commit bd1d9d1

Please sign in to comment.