Skip to content

Commit e902106

Browse files
committed
feat(rehype-shiki): route to CodeTabsWithHash if groupId exists
1 parent de1d09c commit e902106

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎apps/site/mdx/components.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import AlertBox from '@node-core/ui-components/Common/AlertBox';
44
import BadgeGroup from '@node-core/ui-components/Common/BadgeGroup';
55
import Blockquote from '@node-core/ui-components/Common/Blockquote';
66
import MDXCodeTabs from '@node-core/ui-components/MDX/CodeTabs';
7+
import CodeTabsWithHash from '@node-core/ui-components/MDX/CodeTabs/CodeTabsWithHash';
78
import {
89
MDXTooltip,
910
MDXTooltipContent,
@@ -58,6 +59,7 @@ export default {
5859
AlertBox,
5960
// Renders MDX CodeTabs
6061
CodeTabs: MDXCodeTabs,
62+
CodeTabsWithHash,
6163
// Renders Tooltips
6264
MDXTooltip,
6365
MDXTooltipContent,

‎packages/rehype-shiki/src/plugin.mjs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default async function rehypeShikiji(options) {
6767
const codeTabsChildren = [];
6868

6969
let defaultTab = '0';
70+
let groupId;
7071
let currentIndex = index;
7172

7273
while (isCodeBlock(parent?.children[currentIndex])) {
@@ -84,6 +85,11 @@ export default async function rehypeShikiji(options) {
8485
// Map the display names of each variant for the CodeTab
8586
displayNames.push(meta.displayName?.replaceAll('|', '') ?? '');
8687

88+
// Extract groupId if it exists
89+
if (meta.groupId) {
90+
groupId = meta.groupId;
91+
}
92+
8793
codeTabsChildren.push(parent?.children[currentIndex]);
8894

8995
// If `active="true"` is provided in a CodeBox
@@ -102,12 +108,13 @@ export default async function rehypeShikiji(options) {
102108
if (codeTabsChildren.length >= 2) {
103109
const codeTabElement = {
104110
type: 'element',
105-
tagName: 'CodeTabs',
111+
tagName: groupId ? 'CodeTabsWithHash' : 'CodeTabs',
106112
children: codeTabsChildren,
107113
properties: {
108114
languages: languages.join('|'),
109115
displayNames: displayNames.join('|'),
110116
defaultTab,
117+
groupId,
111118
},
112119
};
113120

0 commit comments

Comments
 (0)