summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/utils')
-rw-r--r--packages/cli/src/ui/utils/CodeColorizer.tsx36
1 files changed, 22 insertions, 14 deletions
diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx
index 441fc610..f3e7e8eb 100644
--- a/packages/cli/src/ui/utils/CodeColorizer.tsx
+++ b/packages/cli/src/ui/utils/CodeColorizer.tsx
@@ -66,6 +66,11 @@ function renderHastNode(
// Handle Root Node: Start recursion with initial inherited color
if (node.type === 'root') {
+ // Check if children array is empty - this happens when lowlight can't detect language – fallback to plain text
+ if (!node.children || node.children.length === 0) {
+ return null;
+ }
+
// Pass down the initial inheritedColor (likely undefined from the top call)
// Ensure child type matches expected HAST structure (RootContent is common)
return node.children?.map((child: RootContent, index: number) => (
@@ -105,21 +110,24 @@ export function colorizeCode(
return (
<Text>
- {lines.map((line, index) => (
- <Text key={index}>
- <Text color={activeTheme.colors.Gray}>
- {`${String(index + 1).padStart(padWidth, ' ')} `}
- </Text>
- <Text color={activeTheme.defaultColor}>
- {renderHastNode(
- getHighlightedLines(line),
- activeTheme,
- undefined,
- )}
+ {lines.map((line, index) => {
+ const renderedNode = renderHastNode(
+ getHighlightedLines(line),
+ activeTheme,
+ undefined,
+ );
+
+ const contentToRender = renderedNode !== null ? renderedNode : line;
+ return (
+ <Text key={index}>
+ <Text color={activeTheme.colors.Gray}>
+ {`${String(index + 1).padStart(padWidth, ' ')} `}
+ </Text>
+ <Text color={activeTheme.defaultColor}>{contentToRender}</Text>
+ {index < lines.length - 1 && '\n'}
</Text>
- {index < lines.length - 1 && '\n'}
- </Text>
- ))}
+ );
+ })}
</Text>
);
} catch (error) {