diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx index 19a463fdf..ca069dc55 100644 --- a/src/components/CodeBlock.tsx +++ b/src/components/CodeBlock.tsx @@ -194,7 +194,7 @@ export function CodeBlock({ style={props.style} > {(title || showTypeCopyButton) && ( -
elements (code blocks) under current framework
- const c = child as HastNode
- if (c.type === 'element' && c.tagName === 'pre' && currentFramework) {
- const codeBlockData = extractCodeBlockData(c)
+ if (child.type === 'element' && child.tagName === 'pre') {
+ const codeBlockData = extractCodeBlockData(child)
if (!codeBlockData) continue
- if (!codeBlocksByFramework[currentFramework]) {
- codeBlocksByFramework[currentFramework] = []
- }
-
codeBlocksByFramework[currentFramework].push({
title: codeBlockData.title || 'Untitled',
code: codeBlockData.code,
@@ -259,11 +271,12 @@ function extractFrameworkData(node: HastNode): FrameworkExtraction | null {
}
}
- if (Object.keys(codeBlocksByFramework).length === 0) {
+ // Return null only if no frameworks found at all
+ if (Object.keys(contentByFramework).length === 0) {
return null
}
- return { codeBlocksByFramework }
+ return { codeBlocksByFramework, contentByFramework }
}
function extractTabPanels(node: HastNode): TabExtraction | null {
@@ -416,19 +429,19 @@ export function transformTabsComponent(node: HastNode) {
})
// Store available frameworks for the component
- const availableFrameworks = Object.keys(result.codeBlocksByFramework)
+ const availableFrameworks = Object.keys(result.contentByFramework)
node.properties['data-available-frameworks'] =
JSON.stringify(availableFrameworks)
node.children = availableFrameworks.map((fw) => {
- const blocks = result.codeBlocksByFramework[fw]
+ const content = result.contentByFramework[fw] || []
return {
type: 'element',
tagName: 'md-tab-panel',
properties: {
'data-framework': fw,
},
- children: blocks.map((block) => block.preNode),
+ children: content,
}
})
return