-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathcode-block.tsx
More file actions
34 lines (31 loc) · 854 Bytes
/
code-block.tsx
File metadata and controls
34 lines (31 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { transformerNotationHighlight } from '@shikijs/transformers';
import { codeToHtml } from 'shiki';
import { cn } from '@/lib/utils';
type CodeBlockProps = {
code: string;
lang: string;
codeblock?: {
className?: string;
};
};
export const CodeBlock = async ({ code, lang, codeblock }: CodeBlockProps) => {
const html = await codeToHtml(code, {
lang,
themes: {
light: 'github-light-default',
dark: 'github-dark-default',
},
defaultColor: false,
transformers: [transformerNotationHighlight()],
});
return (
<div
className={cn(
'overflow-auto text-sm py-6 border [&_pre]:!bg-transparent',
codeblock?.className
)}
// biome-ignore lint/security/noDangerouslySetInnerHtml: Shiki generates safe HTML
dangerouslySetInnerHTML={{ __html: html }}
/>
);
};