pydata-sphinx-theme
pydata-sphinx-theme copied to clipboard
make code-block focusable
Fix #1100
That was way more complicated than expected.
3 possible choices are available:
- use pure JS to add the tabindex attributes at run time
- parse the page and search for "pre" elements
- override the
visit_literal_block
method
By looking more carefully at it I realized that not all the "pre" elements are actually generated by docutils (the one included in highlighted code for example are never parsed) so I decided to overwrite the visit_literal_block
to get both the div
including the code elements and the pre
from non highlighted elements.
before: https://pydata-sphinx-theme.readthedocs.io/en/stable/examples/kitchen-sink/blocks.html#code-block
after: https://pydata-sphinx-theme--1104.org.readthedocs.build/en/1104/examples/kitchen-sink/blocks.html#literal-blocks