Fix code-line-numbers links having no accessible name#14662
Open
cderv wants to merge 2 commits into
Open
Conversation
Skylighting's numberSource line numbering emits an empty <a> per line, with the visible number drawn purely via a CSS counter on ::before. Screen readers and axe-core see a focusable link with no discernible text (WCAG 2.4.4/4.1.2). aria-hidden isn't an option since these anchors are real, focusable fragment links, and aria-hidden on a focusable element is itself an axe violation. Instead, set aria-label to the visible line number, computed from any counter-reset offset so custom startFrom values stay correct. Implemented as a postprocessor pass in htmlFormatPostprocessor, which revealjs's htmlFormatExtras also inherits, so one pass covers both.
…14655) Verified against real axe-core 4.10 in a browser: the html fixture (numbered code, no other violation source) now reports zero axe-core violations, and the revealjs fixture's report has no violation targeting a code line-number anchor (only the pre-existing, unrelated slide-menu-button/viewport-meta violations remain, tracked separately).
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Skylighting's
numberSourceline-numbering emits an empty<a href="#cbN-n"></a>as the first child of every code line span, drawing the visible number purely via a CSS counter on::before. Screen readers and axe-core see a focusable link with no discernible text (WCAG 2.4.4/4.1.2link-name).Fix
Set
aria-labelon each line anchor to its visible line number, computed from anycounter-reset: source-line Noffset so customstartFromvalues stay correct. Implemented as a postprocessor pass inhtmlFormatPostprocessor(src/format/html/format-html.ts), which revealjs'shtmlFormatExtrasalso inherits, so one pass covers bothhtmlandrevealjs.aria-hiddenisn't an option here: these anchors are real, focusable fragment links, andaria-hiddenon a focusable element is itself an axe violation.Verified against real axe-core in a browser, now codified as a playwright regression test. On revealjs, the axe report still shows a pre-existing
link-nameviolation from the deck's.slide-menu-buttonchrome, unrelated to this issue and out of scope here.Fixes #14655