From b980a53178d96f63c77ff683934bf4a320e0d768 Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Wed, 11 Mar 2026 20:33:25 +0900 Subject: [PATCH 1/3] fix: prevent grouping consecutive code blocks with the same language Two consecutive code blocks with the same language (e.g., both `mjs`) were incorrectly grouped into a CJS/MJS switchable tab. Add a check to ensure the two code blocks have different languages before creating a switchable code tab. Refs: https://github.com/nodejs/node/pull/62181 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/utils/highlighter.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/highlighter.mjs b/src/utils/highlighter.mjs index 0217f09d..32c2b453 100644 --- a/src/utils/highlighter.mjs +++ b/src/utils/highlighter.mjs @@ -142,8 +142,12 @@ export default function rehypeShikiji() { currentIndex += 1; // Since we only support CJS/MJS switch, we should have exactly 2 elements - // in order to create a switchable code tab - if (codeElements.length === 2) { + // with different languages in order to create a switchable code tab + if ( + codeElements.length === 2 && + codeElements[0].properties.language !== + codeElements[1].properties.language + ) { const switchablePreElement = createElement( 'pre', { From 27433e9f561f0e98992ac654279377b9309624e7 Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Wed, 11 Mar 2026 21:33:52 +0900 Subject: [PATCH 2/3] fix: add optional chaining for defensive null safety --- src/utils/highlighter.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/highlighter.mjs b/src/utils/highlighter.mjs index 32c2b453..c820ea72 100644 --- a/src/utils/highlighter.mjs +++ b/src/utils/highlighter.mjs @@ -145,8 +145,8 @@ export default function rehypeShikiji() { // with different languages in order to create a switchable code tab if ( codeElements.length === 2 && - codeElements[0].properties.language !== - codeElements[1].properties.language + codeElements[0]?.properties?.language !== + codeElements[1]?.properties?.language ) { const switchablePreElement = createElement( 'pre', From 8f46e38211dde32f890388b63e221508f6372182 Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Wed, 11 Mar 2026 23:13:32 +0900 Subject: [PATCH 3/3] fix: update to assume [0] and [1] always exist --- src/utils/highlighter.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/highlighter.mjs b/src/utils/highlighter.mjs index c820ea72..0616e5fa 100644 --- a/src/utils/highlighter.mjs +++ b/src/utils/highlighter.mjs @@ -145,8 +145,8 @@ export default function rehypeShikiji() { // with different languages in order to create a switchable code tab if ( codeElements.length === 2 && - codeElements[0]?.properties?.language !== - codeElements[1]?.properties?.language + codeElements[0].properties?.language !== + codeElements[1].properties?.language ) { const switchablePreElement = createElement( 'pre',