Skip to content

Commit

Permalink
fix: syntax highlighting (#325)
Browse files Browse the repository at this point in the history
Sytax hightlight it was not working because it was handling arrays with
one item as Element instead String.
  • Loading branch information
fraidev authored Jan 8, 2025
1 parent 8a51006 commit a528292
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/theme/CodeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ function maybeStringifyChildren(children: ReactNode): ReactNode {
// The children is now guaranteed to be one/more plain strings

// If child is "$" or "$$" jump to the next line, if not add a space
return React.Children.toArray(children).map((child, index) => {
let nodes = React.Children.toArray(children).map((child, index) => {
if (typeof child === 'string') {
if (index > 0) {
return child.replace(/\$\$?/g, (match) => (match === '$' ? '\n$' : ' '));
}
}
return child;
});

if (nodes.length === 1) {
return nodes[0];
}

return nodes;
}

export default function CodeBlock({
Expand Down

0 comments on commit a528292

Please sign in to comment.