From a0eafea3b1b9bde3f877097985d387103f64e449 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Sun, 7 Jan 2024 22:15:31 -0500 Subject: [PATCH 1/3] Ensure code blocks (
) are keyboard focusable

---
 src/pydata_sphinx_theme/translator.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/pydata_sphinx_theme/translator.py b/src/pydata_sphinx_theme/translator.py
index eb2046bd4..d6e5b69d0 100644
--- a/src/pydata_sphinx_theme/translator.py
+++ b/src/pydata_sphinx_theme/translator.py
@@ -23,9 +23,17 @@ def __init__(self, *args, **kwds):
         self.settings.table_style = "table"
 
     def starttag(self, *args, **kwargs):
-        """Ensure an aria-level is set for any heading role."""
+        """Perform small modifications to tags.
+
+        - ensure aria-level is set for any tag with heading role
+        - ensure 
 tags have tabindex="0".
+        """
         if kwargs.get("ROLE") == "heading" and "ARIA-LEVEL" not in kwargs:
             kwargs["ARIA-LEVEL"] = "2"
+
+        if "pre" in args:
+            kwargs["tabindex"] = "0"
+
         return super().starttag(*args, **kwargs)
 
     def visit_table(self, node):

From de64db199605caefbe0936a0474fc2c102413c1b Mon Sep 17 00:00:00 2001
From: gabalafou 
Date: Sun, 7 Jan 2024 23:28:14 -0500
Subject: [PATCH 2/3] Also cover 
 tags not covered by starttag

---
 src/pydata_sphinx_theme/translator.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/pydata_sphinx_theme/translator.py b/src/pydata_sphinx_theme/translator.py
index d6e5b69d0..5d826a899 100644
--- a/src/pydata_sphinx_theme/translator.py
+++ b/src/pydata_sphinx_theme/translator.py
@@ -3,6 +3,7 @@
 import types
 
 import sphinx
+from docutils import nodes
 from packaging.version import Version
 from sphinx.application import Sphinx
 from sphinx.ext.autosummary import autosummary_table
@@ -36,6 +37,22 @@ def starttag(self, *args, **kwargs):
 
         return super().starttag(*args, **kwargs)
 
+    def visit_literal_block(self, node):
+        """Modify literal blocks.
+
+        - ensure tabindex="0" for 
 tags buried in the HTML tree that Sphinx
+          (with Pygments) generates for literal blocks
+        """
+        try:
+            super().visit_literal_block(node)
+        except nodes.SkipNode:
+            # If the super method raises nodes.SkipNode, then we know it
+            # executed successfully and appended to self.body a string of HTML
+            # representing the code block, which we then modify.
+            html_string = self.body[-1]
+            self.body[-1] = html_string.replace("
Date: Fri, 5 Apr 2024 16:08:03 +0100
Subject: [PATCH 3/3] Update src/pydata_sphinx_theme/translator.py

Co-authored-by: gabalafou 
---
 src/pydata_sphinx_theme/translator.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pydata_sphinx_theme/translator.py b/src/pydata_sphinx_theme/translator.py
index 5d826a899..b05bc8307 100644
--- a/src/pydata_sphinx_theme/translator.py
+++ b/src/pydata_sphinx_theme/translator.py
@@ -40,8 +40,8 @@ def starttag(self, *args, **kwargs):
     def visit_literal_block(self, node):
         """Modify literal blocks.
 
-        - ensure tabindex="0" for 
 tags buried in the HTML tree that Sphinx
-          (with Pygments) generates for literal blocks
+        - add tabindex="0" to 
 tags within the HTML tree of the literal
+          block
         """
         try:
             super().visit_literal_block(node)