Skip to content

Commit 38c58bc

Browse files
okuryuCopilot
andauthored
fix: prevent grouping consecutive code blocks with the same language (#667)
* 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: nodejs/node#62181 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: add optional chaining for defensive null safety * fix: update to assume [0] and [1] always exist --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 84f6dac commit 38c58bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/utils/highlighter.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ export default function rehypeShikiji() {
142142
currentIndex += 1;
143143

144144
// Since we only support CJS/MJS switch, we should have exactly 2 elements
145-
// in order to create a switchable code tab
146-
if (codeElements.length === 2) {
145+
// with different languages in order to create a switchable code tab
146+
if (
147+
codeElements.length === 2 &&
148+
codeElements[0].properties?.language !==
149+
codeElements[1].properties?.language
150+
) {
147151
const switchablePreElement = createElement(
148152
'pre',
149153
{

0 commit comments

Comments
 (0)