pydata-sphinx-theme icon indicating copy to clipboard operation
pydata-sphinx-theme copied to clipboard

make code-block focusable

Open 12rambau opened this issue 1 year ago • 9 comments

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

12rambau avatar Jan 07 '23 14:01 12rambau