Skip to content

Commit 267e6ef

Browse files
refactor: replace legacy syntax highlighters with ShowCode
- ReadFileTool: swap inline CodeBlock + duplicated header/button JSX for a single <ShowCode> — removes the fragile [&>div>div]:max-h-[300px] deep selector and the duplicated open-in-pane button pattern flagged in code review - MarkdownRenderer/CodeBlock (desktop): replace react-syntax-highlighter (Prism) with ShowCode, aligning markdown code fences with the shared Shiki-based highlighter used throughout the chat UI
1 parent 818059c commit 267e6ef

2 files changed

Lines changed: 19 additions & 37 deletions

File tree

apps/desktop/src/renderer/components/MarkdownRenderer/components/CodeBlock/CodeBlock.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { mermaid } from "@streamdown/mermaid";
2+
import { ShowCode } from "@superset/ui/ai-elements/show-code";
23
import type { ReactNode } from "react";
3-
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
4-
import {
5-
oneDark,
6-
oneLight,
7-
} from "react-syntax-highlighter/dist/esm/styles/prism";
84
import { useTheme } from "renderer/stores";
95
import { Streamdown } from "streamdown";
106

@@ -26,7 +22,6 @@ interface CodeBlockProps {
2622
export function CodeBlock({ children, className, node }: CodeBlockProps) {
2723
const theme = useTheme();
2824
const isDark = theme?.type !== "light";
29-
const syntaxStyle = isDark ? oneDark : oneLight;
3025

3126
const match = /language-(\w+)/.exec(className || "");
3227
const language = match ? match[1] : undefined;
@@ -56,13 +51,12 @@ export function CodeBlock({ children, className, node }: CodeBlockProps) {
5651
}
5752

5853
return (
59-
<SyntaxHighlighter
60-
style={syntaxStyle as Record<string, React.CSSProperties>}
61-
language={language ?? "text"}
62-
PreTag="div"
63-
className="rounded-md text-sm"
64-
>
65-
{codeString}
66-
</SyntaxHighlighter>
54+
<ShowCode
55+
className="my-4"
56+
// biome-ignore lint/suspicious/noExplicitAny: ShowCode accepts BundledLanguage; language is an untyped string here
57+
language={language as any}
58+
code={codeString}
59+
showLineNumbers
60+
/>
6761
);
6862
}

packages/ui/src/components/ai-elements/read-file-tool.tsx

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { FileIcon } from "lucide-react";
44
import type { BundledLanguage } from "shiki";
55
import { ClickableFilePath } from "./clickable-file-path";
6-
import { CodeBlock } from "./code-block";
6+
import { ShowCode } from "./show-code";
77
import { ToolCallRow } from "./tool-call-row";
88

99
export type ReadFileToolProps = {
@@ -39,34 +39,22 @@ export function ReadFileTool({
3939
return (
4040
<ToolCallRow
4141
className={className}
42-
description={
43-
<ClickableFilePath path={filename} onOpen={onOpenInPane} />
44-
}
42+
description={<ClickableFilePath path={filename} onOpen={onOpenInPane} />}
4543
icon={FileIcon}
4644
isError={isError}
4745
isPending={isPending}
4846
title="Read"
4947
>
5048
<div className="py-1.5 pl-2">
51-
<div className="overflow-hidden rounded-md border border-border">
52-
<div className="flex items-center gap-2 border-b border-border bg-muted/50 px-3 py-1.5 font-mono text-xs">
53-
<ClickableFilePath
54-
path={filename}
55-
onOpen={onOpenInPane}
56-
className="text-foreground"
57-
/>
58-
{lineRange && (
59-
<span className="text-muted-foreground">{lineRange}</span>
60-
)}
61-
</div>
62-
<CodeBlock
63-
className="rounded-none border-0 [&>div>div]:max-h-[300px] [&_pre]:!p-2"
64-
code={content}
65-
colorize={false}
66-
language={language}
67-
showLineNumbers
68-
/>
69-
</div>
49+
<ShowCode
50+
code={content}
51+
colorize={false}
52+
filename={filename}
53+
language={language}
54+
lineRange={lineRange}
55+
onOpen={onOpenInPane}
56+
showLineNumbers
57+
/>
7058
</div>
7159
</ToolCallRow>
7260
);

0 commit comments

Comments
 (0)