Skip to content

Commit

Permalink
Patch gatsby-remark-shiki-twoslash to add in tabindex (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Oct 16, 2024
1 parent ad02d26 commit e2b46f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"patchedDependencies": {
"react-server-dom-webpack@0.0.0-experimental-c8b778b7f-20220825": "patches/react-server-dom-webpack@0.0.0-experimental-c8b778b7f-20220825.patch",
"react-intl@3.12.1": "patches/react-intl@3.12.1.patch"
"react-intl@3.12.1": "patches/react-intl@3.12.1.patch",
"gatsby-remark-shiki-twoslash@3.0.38": "patches/gatsby-remark-shiki-twoslash@3.0.38.patch"
}
},
"jest": {
Expand Down
24 changes: 24 additions & 0 deletions patches/gatsby-remark-shiki-twoslash@3.0.38.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 6036d987fc2889ec9bc230f7774013ae4f736dd9..0000000000000000000000000000000000000000
diff --git a/src/index.js b/src/index.js
index e16676ef50b660d520a0efc0b73b68411db349af..bb21bc500a34ac31063774ba4ba133daed2c4f14 100755
--- a/src/index.js
+++ b/src/index.js
@@ -4,7 +4,15 @@ const { setupForFile, remarkVisitor } = require("remark-shiki-twoslash")

const remarkShiki = async function ({ markdownAST }, userConfig) {
const {settings, highlighters} = await setupForFile(userConfig)
- visit(markdownAST, "code", remarkVisitor(highlighters, settings))
+ const orig = remarkVisitor(highlighters, settings)
+ /** @type {typeof orig} */
+ const visitor = (node) => {
+ orig(node)
+ // Hack to make shiki twoslash code blocks focusable; not needed in modern shiki but we're using an old version
+ node.value = node.value.replace(/(class='code-container')/g, "$1 tabindex='0'")
+ }
+ visit(markdownAST, "code", visitor);
}

module.exports = remarkShiki
+
7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2b46f0

Please sign in to comment.