-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tabindex and focus states to code blocks
This is required for accessibility reasons. Because some code blocks have scrollbars they need to be focusable using a keyboard. I've copied the styles from the design system's documentation (see the code blocks in the HTML / Nunjucks tabs here: https://design-system.service.gov.uk/components/button/) The implementation is simple when syntax highlighting is not enabled, because we can simply implement `block_code` to surround the code with the markup we want. When syntax highlighting is enabled it's a bit more complicated. Middleman already `include`s its own implementation of `block_code`, which renders the source code highlighted with spans. This method doesn't look like it would be easy to customise, so instead I've resorted to post-processing the HTML (i.e. replacing the attributes on the `<pre>` tag using a regex). Testing this was a bit tricky, because you need to monkey patch the class to include the `block_code` method. I had to clone the class and patch the clone to do avoid affecting other tests.
- Loading branch information
1 parent
3de782e
commit 67994d8
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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