From e2b46f065a01947fdc2a803ecc26c7dd625e3ab0 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:23:16 -0700 Subject: [PATCH] Patch gatsby-remark-shiki-twoslash to add in tabindex (#3257) --- package.json | 3 ++- .../gatsby-remark-shiki-twoslash@3.0.38.patch | 24 +++++++++++++++++++ pnpm-lock.yaml | 7 ++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 patches/gatsby-remark-shiki-twoslash@3.0.38.patch diff --git a/package.json b/package.json index 906a82f5cde2..fe8d510e7d46 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/patches/gatsby-remark-shiki-twoslash@3.0.38.patch b/patches/gatsby-remark-shiki-twoslash@3.0.38.patch new file mode 100644 index 000000000000..b398a78298ed --- /dev/null +++ b/patches/gatsby-remark-shiki-twoslash@3.0.38.patch @@ -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 ++ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3db3f16496f3..28b0336d9818 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ overrides: sharp: 0.28.1 patchedDependencies: + gatsby-remark-shiki-twoslash@3.0.38: + hash: prtace25mhevaarvvizifk2ksu + path: patches/gatsby-remark-shiki-twoslash@3.0.38.patch react-intl@3.12.1: hash: yqkzm4v5lxjbatodvsvpq7o7bq path: patches/react-intl@3.12.1.patch @@ -413,7 +416,7 @@ importers: version: 6.13.1(gatsby@5.13.5(babel-eslint@10.1.0(eslint@7.32.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(type-fest@4.18.2)(typescript@5.6.2)) gatsby-remark-shiki-twoslash: specifier: ^3.0.36 - version: 3.0.38 + version: 3.0.38(patch_hash=prtace25mhevaarvvizifk2ksu) gatsby-remark-smartypants: specifier: ^6.6.0 version: 6.13.1(gatsby@5.13.5(babel-eslint@10.1.0(eslint@7.32.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(type-fest@4.18.2)(typescript@5.6.2)) @@ -17416,7 +17419,7 @@ snapshots: lodash: 4.17.21 unist-util-visit: 2.0.3 - gatsby-remark-shiki-twoslash@3.0.38: + gatsby-remark-shiki-twoslash@3.0.38(patch_hash=prtace25mhevaarvvizifk2ksu): dependencies: remark-shiki-twoslash: 3.1.3(typescript@5.6.2) typescript: 5.6.2