Skip to content

Commit 20b9080

Browse files
committed
fix(web): fix MarkdownTable to handle inline code in table cells
1 parent 6d5d2f0 commit 20b9080

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

web/src/components/docs/mdx/markdown-table.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ interface MarkdownTableProps {
88
children: React.ReactNode
99
}
1010

11+
// Recursively extract text content from React elements
12+
function extractTextContent(node: React.ReactNode): string {
13+
if (node === null || node === undefined) {
14+
return ''
15+
}
16+
if (typeof node === 'string' || typeof node === 'number') {
17+
return String(node)
18+
}
19+
if (Array.isArray(node)) {
20+
return node.map(extractTextContent).join('')
21+
}
22+
if (typeof node === 'object' && 'props' in node) {
23+
const element = node as React.ReactElement
24+
return extractTextContent(element.props.children)
25+
}
26+
return ''
27+
}
28+
1129
export function MarkdownTable({ children }: MarkdownTableProps) {
1230
const [copied, setCopied] = useState(false)
1331

1432
const { content, tableData } = useMemo(() => {
15-
// Extract content from children
16-
let contentStr = ''
17-
if (typeof children === 'string') {
18-
contentStr = children
19-
} else if (Array.isArray(children)) {
20-
contentStr = children
21-
.map((child) => (typeof child === 'string' ? child : ''))
22-
.join('')
23-
} else if (
24-
children &&
25-
typeof children === 'object' &&
26-
'props' in children
27-
) {
28-
contentStr =
29-
typeof children.props.children === 'string'
30-
? children.props.children
31-
: Array.isArray(children.props.children)
32-
? children.props.children.join('')
33-
: ''
34-
}
33+
// Extract content from children (recursively handles React elements)
34+
const contentStr = extractTextContent(children)
3535

3636
// Parse table data from markdown string
3737
const lines = contentStr.trim().split('\n')

0 commit comments

Comments
 (0)