From 97215553430ff15e5faf7efcbdd9b018585303a6 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 4 Nov 2024 21:14:27 +0000 Subject: [PATCH 1/6] Add a axe rule which can detect linked pdf files Also handles if they have query params or anchors on the link --- src/pageScanner/rules/link-pdf.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/pageScanner/rules/link-pdf.js diff --git a/src/pageScanner/rules/link-pdf.js b/src/pageScanner/rules/link-pdf.js new file mode 100644 index 00000000..84e064b9 --- /dev/null +++ b/src/pageScanner/rules/link-pdf.js @@ -0,0 +1,17 @@ +/** + * Detects linked PDFs. + */ +export default { + id: 'link_pdf', + selector: 'a[href$=".pdf"], a[href$=".PDF"], a[href*=".pdf?"], a[href*=".PDF?"], a[href*=".pdf#"], a[href*=".PDF#"]', + excludeHidden: false, + tags: [ + 'cat.custom', + ], + metadata: { + description: 'Links to PDFs typically should be checked.', + }, + all: [], + any: [ 'always-fail' ], + none: [], +}; From 667e76366f5b376c979ac7b451e87d51a1d999f5 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 4 Nov 2024 21:15:16 +0000 Subject: [PATCH 2/6] Include the link_pdf in axe scanner and the always-fail check --- src/pageScanner/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pageScanner/index.js b/src/pageScanner/index.js index d90c8552..2f4f1a7d 100644 --- a/src/pageScanner/index.js +++ b/src/pageScanner/index.js @@ -22,10 +22,11 @@ import brokenAnchorLink from './rules/broken-anchor-link'; import anchorExists from './checks/anchor-exists'; import labelExtended from './rules/extended/label'; import imageInputHasAlt from './checks/image-input-has-alt'; +import linkPDF from './rules/link-pdf'; //TODO: examples: //import customRule1 from './rules/custom-rule-1'; -//import alwaysFail from './checks/always-fail'; +import alwaysFail from './checks/always-fail'; //TODO: //see: https://github.com/dequelabs/axe-core/blob/develop/doc/developer-guide.md#api-reference @@ -62,11 +63,12 @@ const scan = async ( textJustified, linkTargetBlank, linkAmbiguousText, + linkPDF, brokenAnchorLink, labelExtended, ], checks: [ - //alwaysFail, + alwaysFail, elementIsAUTag, elementWithUnderline, paragraphStyledAsHeader, @@ -101,6 +103,7 @@ const scan = async ( textJustified.id, linkTargetBlank.id, linkAmbiguousText.id, + linkPDF.id, brokenAnchorLink.id, labelExtended.id, ], From 28c072240e3567faf4653817a6886fec71ee6d7d Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 4 Nov 2024 21:15:55 +0000 Subject: [PATCH 3/6] Make the link_pdf rule part of the JS ruleset --- includes/rules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/rules.php b/includes/rules.php index 2822b52d..479c0e4e 100644 --- a/includes/rules.php +++ b/includes/rules.php @@ -250,6 +250,7 @@ 'slug' => 'link_pdf', 'rule_type' => 'warning', 'summary' => esc_html__( 'A Link to PDF warning means that one or more of the links on your page or post directs to a PDF file. This warning is a reminder to manually test the linked PDF for accessibility and to confirm that it conforms to all relevant WCAG guidelines. To resolve a Link to PDF warning, you need to: (1) ensure a direct link to view or download the document is present if you\'re using a plugin to embed it on the page; (2) ensure the link to the document warns users it is a link to a document by displaying the specific file extension in the link anchor; and (3) test and remediate your document for accessibility errors. After determining your file is fully accessible, you can safely “Ignore” the warning.', 'accessibility-checker' ), + 'ruleset' => 'js', ], [ 'title' => esc_html__( 'Link to Non-HTML File', 'accessibility-checker' ), From 303157f91eb60722ebcf65b7c7693a209c4f0f66 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 4 Nov 2024 21:17:41 +0000 Subject: [PATCH 4/6] Remove the link_pdf php rule, this is superseded by the js rule --- includes/rules/link_pdf.php | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 includes/rules/link_pdf.php diff --git a/includes/rules/link_pdf.php b/includes/rules/link_pdf.php deleted file mode 100644 index 62bd9bd7..00000000 --- a/includes/rules/link_pdf.php +++ /dev/null @@ -1,32 +0,0 @@ -find( 'a' ); - - foreach ( $as as $a ) { - - if ( $a->getAttribute( 'href' ) ) { - if ( strpos( strtolower( $a ), '.pdf' ) ) { - $link_code = $a; - - $errors[] = $link_code; - } - } - } - return $errors; -} From 53e2c41997781f408fb715f680f0a7666590640e Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Tue, 5 Nov 2024 21:26:26 +0000 Subject: [PATCH 5/6] Add a JS scan rule for ms-office-files --- src/pageScanner/index.js | 3 +++ src/pageScanner/rules/link-ms-office-file.js | 26 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/pageScanner/rules/link-ms-office-file.js diff --git a/src/pageScanner/index.js b/src/pageScanner/index.js index 2f4f1a7d..a25fd24d 100644 --- a/src/pageScanner/index.js +++ b/src/pageScanner/index.js @@ -23,6 +23,7 @@ import anchorExists from './checks/anchor-exists'; import labelExtended from './rules/extended/label'; import imageInputHasAlt from './checks/image-input-has-alt'; import linkPDF from './rules/link-pdf'; +import linkMsOfficeFile from './rules/link-ms-office-file'; //TODO: examples: //import customRule1 from './rules/custom-rule-1'; @@ -64,6 +65,7 @@ const scan = async ( linkTargetBlank, linkAmbiguousText, linkPDF, + linkMsOfficeFile, brokenAnchorLink, labelExtended, ], @@ -104,6 +106,7 @@ const scan = async ( linkTargetBlank.id, linkAmbiguousText.id, linkPDF.id, + linkMsOfficeFile.id, brokenAnchorLink.id, labelExtended.id, ], diff --git a/src/pageScanner/rules/link-ms-office-file.js b/src/pageScanner/rules/link-ms-office-file.js new file mode 100644 index 00000000..7d73fba3 --- /dev/null +++ b/src/pageScanner/rules/link-ms-office-file.js @@ -0,0 +1,26 @@ +/** + * Detects linked MS Office files. + */ + +const msOfficeFileExtensions = [ '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pps', '.ppsx' ]; + +// This generates a very long list of selectors, 6 in total for each extension: extension at the end, +// extension within having query vars, extension within having #anchors plus uppercase versions of the +// file extension for each one of these cases. It is still quicker that iterating through all the links +// on the page and checking the href in a matches. +const selectorString = msOfficeFileExtensions.map( ( extension ) => `a[href$="${ extension }"], a[href$="${ extension.toUpperCase() }"], a[href*="${ extension }?"], a[href*="${ extension.toUpperCase() }?"], a[href*="${ extension }#"], a[href*="${ extension.toUpperCase() }#"]` ).join( ', ' ); + +export default { + id: 'link_ms_office_file', + selector: selectorString, + excludeHidden: false, + tags: [ + 'cat.custom', + ], + metadata: { + description: 'Links to MS Office documents typically should be checked.', + }, + all: [], + any: [ 'always-fail' ], + none: [], +}; From 3c54a018ae5010b38882b831c977ab9b290e6bd6 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Tue, 5 Nov 2024 21:27:01 +0000 Subject: [PATCH 6/6] Set link_ms_office_file to JS ruleset and remove the php rule file --- includes/rules.php | 2 +- includes/rules/link_ms_office_file.php | 44 -------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 includes/rules/link_ms_office_file.php diff --git a/includes/rules.php b/includes/rules.php index 479c0e4e..cc376cca 100644 --- a/includes/rules.php +++ b/includes/rules.php @@ -9,7 +9,6 @@ TabindexFix, AddLabelToUnlabelledFormFieldsFix, CommentSearchLabelFix, - ReadMoreAddTitleFix, PreventLinksOpeningNewWindowFix, HTMLLangAndDirFix, AddMissingOrEmptyPageTitleFix, @@ -243,6 +242,7 @@ 'slug' => 'link_ms_office_file', 'rule_type' => 'warning', 'summary' => esc_html__( 'A Link to MS Office File warning means that one or more of the links on your page or post directs to a file with one of the following file extensions: .doc, .docx, .xls, .xlsx, .ppt, .pptx, .pps or .ppsx. This warning appears when an MS Office file is present as a reminder to manually test your Word documents, PowerPoint presentations, and Excel spreadsheets for accessibility and to confirm that they conform to all relevant WCAG guidelines. To resolve a Link to MS Office File warning, you need to: (1) ensure a direct link to view or download the document is present if you\'re using a plugin to embed it on the page; (2) ensure the link to the document warns users it is a link to a document by displaying the specific file extension in the link anchor; and (3) test and remediate your MS Office file for accessibility errors. After determining your file is fully accessible, you can safely “Ignore” the warning.', 'accessibility-checker' ), + 'ruleset' => 'js', ], [ 'title' => esc_html__( 'Link to PDF', 'accessibility-checker' ), diff --git a/includes/rules/link_ms_office_file.php b/includes/rules/link_ms_office_file.php deleted file mode 100644 index cd3afad9..00000000 --- a/includes/rules/link_ms_office_file.php +++ /dev/null @@ -1,44 +0,0 @@ -find( 'a' ); - foreach ( $as as $a ) { - // Get the href attribute of the anchor tag. - $href = $a->getAttribute( 'href' ); - if ( $href ) { - // Remove any query or fragment from the URL. - $url_components = wp_parse_url( $href ); - $clean_path = $url_components['path'] ?? ''; - - // Check if cleaned URL contains any file extension. - foreach ( $file_extensions as $file_extension ) { - // Check if the cleaned path ends with a file extension. - if ( substr( strtolower( $clean_path ), -strlen( $file_extension ) ) === $file_extension ) { - // If match found, store the outer HTML of the anchor tag. - $link_code = $a->outertext; - $errors[] = $link_code; - // No need to check other extensions for this link. - break; - } - } - } - } - return $errors; -}