2025-12-06 12:46:40 +09:00
|
|
|
"use client"
|
2025-12-03 21:49:34 +09:00
|
|
|
|
2025-12-06 12:46:40 +09:00
|
|
|
import { Highlight, themes } from "prism-react-renderer"
|
2025-12-03 21:49:34 +09:00
|
|
|
|
|
|
|
|
interface CodeBlockProps {
|
2025-12-06 12:46:40 +09:00
|
|
|
code: string
|
|
|
|
|
language?: "xml" | "json"
|
2025-12-03 21:49:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function CodeBlock({ code, language = "xml" }: CodeBlockProps) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="overflow-hidden w-full">
|
|
|
|
|
<Highlight theme={themes.github} code={code} language={language}>
|
2025-12-06 12:46:40 +09:00
|
|
|
{({
|
|
|
|
|
className,
|
|
|
|
|
style,
|
|
|
|
|
tokens,
|
|
|
|
|
getLineProps,
|
|
|
|
|
getTokenProps,
|
|
|
|
|
}) => (
|
2025-12-03 21:49:34 +09:00
|
|
|
<pre
|
|
|
|
|
className="text-[11px] leading-relaxed overflow-x-auto overflow-y-auto max-h-48 scrollbar-thin break-all"
|
|
|
|
|
style={{
|
|
|
|
|
...style,
|
2025-12-06 12:46:40 +09:00
|
|
|
fontFamily:
|
|
|
|
|
"var(--font-mono), ui-monospace, monospace",
|
2025-12-03 21:49:34 +09:00
|
|
|
backgroundColor: "transparent",
|
|
|
|
|
margin: 0,
|
|
|
|
|
padding: 0,
|
|
|
|
|
wordBreak: "break-all",
|
|
|
|
|
whiteSpace: "pre-wrap",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{tokens.map((line, i) => (
|
2025-12-06 12:46:40 +09:00
|
|
|
<div
|
|
|
|
|
key={i}
|
|
|
|
|
{...getLineProps({ line })}
|
|
|
|
|
style={{ wordBreak: "break-all" }}
|
|
|
|
|
>
|
2025-12-03 21:49:34 +09:00
|
|
|
{line.map((token, key) => (
|
2025-12-06 12:46:40 +09:00
|
|
|
<span
|
|
|
|
|
key={key}
|
|
|
|
|
{...getTokenProps({ token })}
|
|
|
|
|
/>
|
2025-12-03 21:49:34 +09:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</pre>
|
|
|
|
|
)}
|
|
|
|
|
</Highlight>
|
|
|
|
|
</div>
|
2025-12-06 12:46:40 +09:00
|
|
|
)
|
2025-12-03 21:49:34 +09:00
|
|
|
}
|