Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [DO NOT MERGE] v4.1.3 diff #3

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
da2deae
changed package name to denote DAISY fork
danielweck Jan 19, 2021
bdcf58d
initial patching (scripts/axe-patch-is-aria-role-allowed.js scripts/a…
danielweck Jan 19, 2021
5830ea9
Mocha fast bail
danielweck Jan 19, 2021
8b3740d
semver is same as Axe Core but with DAISY addon suffix. Also added NP…
danielweck Jan 19, 2021
723b98a
semver is reflected in auto-generated doc
danielweck Jan 19, 2021
2e70235
added unit tests for implicit/explicit and DPUB role parsing
danielweck Jan 19, 2021
4ce706d
Scoped NPM package name, and files selection for NPM publish
danielweck Jan 19, 2021
1c9a0b2
NPM public publish
danielweck Jan 19, 2021
6590f7f
Merge branch 'v4.1.1_DAISY' into v4.1.2_DAISY
danielweck Feb 16, 2021
ea67596
rules MD
danielweck Feb 16, 2021
e04a57a
ignore epub:type
danielweck Feb 18, 2021
af3e209
Merge branch 'v4.1.2_DAISY' into v4.1.3_DAISY
danielweck Mar 10, 2021
161d97e
Unit tests require package.json version without canary or arbitrary e…
danielweck Mar 10, 2021
2a6ab7e
landmark-one-main now with page-no-duplicate-main in addition to page…
danielweck Mar 10, 2021
dae726f
doc: landmark-one-main now with page-no-duplicate-main in addition to…
danielweck Mar 10, 2021
2b5bb2d
intermediary commit (Axe hook seems to stash things in the working co…
danielweck Mar 10, 2021
6121f22
main element and div with role
danielweck Mar 10, 2021
10be613
added unit test for landmark-no-duplicate-main to pass content with n…
danielweck Mar 10, 2021
72707cf
matching-aria-role check port (untranslated)
danielweck Mar 10, 2021
45529c1
epub-type-has-matching-role pagebreak-label ported from Ace (translat…
danielweck Mar 10, 2021
5e5e6a7
working XHTML unit tests for EPUB in Axe! (port from Ace)
danielweck Mar 11, 2021
e460f1d
page-break label test (check)
danielweck Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
matching-aria-role check port (untranslated)
danielweck committed Mar 10, 2021

Verified

This commit was signed with the committer’s verified signature.
rouault Even Rouault
commit 72707cf6121f9aef0d2e74676edaf882f428c8e3
182 changes: 182 additions & 0 deletions lib/core/public/configure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { hasReporter } from './reporter';
import { configureStandards } from '../../standards';
import matchesSelector from '../../core/utils/element-matches';
import { tokenList } from '../../core/utils';
import { getRole } from '../../commons/aria';

function configure(spec) {
var audit;
@@ -44,6 +47,185 @@ function configure(spec) {
audit.reporter = spec.reporter;
}

// DAISY-AXE
if (!spec.checks) {
spec.checks = [];
}
spec.checks.push({
id: 'matching-aria-role',
// eslint-disable-next-line no-unused-vars
evaluate: function evaluate(node, options, virtualNode, context) {
// https://idpf.github.io/epub-guides/epub-aria-authoring/#sec-mappings
// https://www.w3.org/TR/dpub-aam-1.0/#mapping_role_table
// https://w3c.github.io/publ-cg/guides/aria-mapping.html#mapping-table
const mappings = new Map([
['abstract', 'doc-abstract'],
['acknowledgments', 'doc-acknowledgments'],
['afterword', 'doc-afterword'],
// ['answer', '??'],
// ['answers', '??'],
['appendix', 'doc-appendix'],
// ['assessment', '??'],
// ['assessments', '??'],
// ['backmatter', '??'],
// ['balloon', '??'],
// ['backlink', 'doc-backlink'], // ??
['biblioentry', 'doc-biblioentry'],
['bibliography', 'doc-bibliography'],
['biblioref', 'doc-biblioref'],
// ['bodymatter', '??'],
// ['bridgehead', '??'],
// ['case-study', '??'],
['chapter', 'doc-chapter'],
['colophon', 'doc-colophon'],
// ['concluding-sentence', '??'],
['conclusion', 'doc-conclusion'],
// ['contributors', '??'],
// ['copyright-page', '??'],
// ['cover', '??'],
// ['cover-image', 'doc-cover'], // ??
// ['covertitle', '??'],
['credit', 'doc-credit'],
['credits', 'doc-credits'],
['dedication', 'doc-dedication'],
// ['division', '??'],
['endnote', 'doc-endnote'],
['endnotes', 'doc-endnotes'],
['epigraph', 'doc-epigraph'],
['epilogue', 'doc-epilogue'],
['errata', 'doc-errata'],
// ['example', 'doc-example'],
// ['feedback', '??'],
['figure', 'figure'], // ARIA
// ['fill-in-the-blank-problem', '??'],
['footnote', 'doc-footnote'],
// ['footnotes', '??'],
['foreword', 'doc-foreword'],
// ['frontmatter', '??'],
// ['fulltitle', '??'],
// ['general-problem', '??'],
['glossary', 'doc-glossary'],
['glossdef', 'definition'], // ARIA
['glossref', 'doc-glossref'],
['glossterm', 'term'], // ARIA
// ['halftitle', '??'],
// ['halftitlepage', '??'],
// ['imprimatur', '??'],
// ['imprint', '??'],
['help', 'doc-tip'], // ??
['index', 'doc-index'],
// ['index-editor-note', '??'],
// ['index-entry', '??'],
// ['index-entry-list', '??'],
// ['index-group', '??'],
// ['index-headnotes', '??'],
// ['index-legend', '??'],
// ['index-locator', '??'],
// ['index-locator-list', '??'],
// ['index-locator-range', '??'],
// ['index-term', '??'],
// ['index-term-categories', '??'],
// ['index-term-category', '??'],
// ['index-xref-preferred', '??'],
// ['index-xref-related', '??'],
['introduction', 'doc-introduction'],
// ['keyword', '??'],
// ['keywords', '??'],
// ['label', '??'],
['landmarks', 'directory'], // ARIA
// ['learning-objective', '??'],
// ['learning-objectives', '??'],
// ['learning-outcome', '??'],
// ['learning-outcomes', '??'],
// ['learning-resource', '??'],
// ['learning-resources', '??'],
// ['learning-standard', '??'],
// ['learning-standards', '??'],
['list', 'list'], // ARIA
['list-item', 'listitem'], // ARIA
// ['loa', '??'],
// ['loi', '??'],
// ['lot', '??'],
// ['lov', '??'],
// ['match-problem', '??'],
// ['multiple-choice-problem', '??'],
['noteref', 'doc-noteref'],
['notice', 'doc-notice'],
// ['ordinal', '??'],
// ['other-credits', '??'],
['page-list', 'doc-pagelist'],
['pagebreak', 'doc-pagebreak'],
// ['panel', '??'],
// ['panel-group', '??'],
['part', 'doc-part'],
// ['practice', '??'],
// ['practices', '??'],
// ['preamble', '??'],
['preface', 'doc-preface'],
['prologue', 'doc-prologue'],
['pullquote', 'doc-pullquote'],
['qna', 'doc-qna'],
// ['question', '??'],
['referrer', 'doc-backlink'],
// ['revision-history', '??'],
// ['seriespage', '??'],
// ['sound-area', '??'],
// ['subchapter', '??'],
['subtitle', 'doc-subtitle'],
['table', 'table'],
['table-cell', 'cell'],
['table-row', 'row'],
// ['text-area', '??'],
['tip', 'doc-tip'],
// ['title', '??'],
// ['titlepage', '??'],
['toc', 'doc-toc']
// ['toc-brief', '??'],
// ['topic-sentence', '??'],
// ['true-false-problem', '??'],
// ['volume', '??'],
]);

if (node.hasAttributeNS('http://www.idpf.org/2007/ops', 'type')) {
// abort if descendant of landmarks nav (nav with epub:type=landmarks)
if (matchesSelector(node, 'nav[*|type~="landmarks"] *')) {
return true;
}

// iterate for each epub:type value
var types = tokenList(
node.getAttributeNS('http://www.idpf.org/2007/ops', 'type')
);
for (const type of types) {
// If there is a 1-1 mapping, check that the role is set (best practice)
if (mappings.has(type)) {
// Note: using axe’s `getRole` util returns the effective role of the element
// (either explicitly set with the role attribute or implicit)
// So this works for types mapping to core ARIA roles (eg. glossref/glossterm).
return mappings.get(type) === getRole(node, { dpub: true });
}
}
}

return true;
},
metadata: {
impact: 'minor',
messages: {
// eslint-disable-next-line no-unused-vars
pass: function anonymous(it) {
return 'Element has an ARIA role matching its epub:type';
},
// eslint-disable-next-line no-unused-vars
fail: function anonymous(it) {
return 'Element has no ARIA role matching its epub:type';
},
incomplete: ''
}
}
});
// DAISY-AXE

if (spec.checks) {
if (!Array.isArray(spec.checks)) {
throw new TypeError('Checks property must be an array');