Skip to content

Commit a528292

Browse files
authored
fix: syntax highlighting (#325)
Sytax hightlight it was not working because it was handling arrays with one item as Element instead String.
1 parent 8a51006 commit a528292

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/theme/CodeBlock/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ function maybeStringifyChildren(children: ReactNode): ReactNode {
1919
// The children is now guaranteed to be one/more plain strings
2020

2121
// If child is "$" or "$$" jump to the next line, if not add a space
22-
return React.Children.toArray(children).map((child, index) => {
22+
let nodes = React.Children.toArray(children).map((child, index) => {
2323
if (typeof child === 'string') {
2424
if (index > 0) {
2525
return child.replace(/\$\$?/g, (match) => (match === '$' ? '\n$' : ' '));
2626
}
2727
}
2828
return child;
2929
});
30+
31+
if (nodes.length === 1) {
32+
return nodes[0];
33+
}
34+
35+
return nodes;
3036
}
3137

3238
export default function CodeBlock({

0 commit comments

Comments
 (0)