-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy pathMarkdownCodeBlock.tsx
More file actions
36 lines (29 loc) · 900 Bytes
/
MarkdownCodeBlock.tsx
File metadata and controls
36 lines (29 loc) · 900 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
35
36
import { type Theme, useShikiHighlighter } from 'react-shiki';
import CopyButton from '~/components/Package/CopyButton';
import tw from '~/util/tailwind';
type Props = {
code: string;
lang: string;
theme: Theme;
};
const SHIKI_OPTS = { langAlias: { gradle: 'groovy' } } as const;
export default function MarkdownCodeBlock({ code, theme, lang }: Props) {
const highlighter = useShikiHighlighter(code, lang, theme, SHIKI_OPTS);
const copyButton = <CopyButton data={code} tooltip="Copy code" label="Copy code to clipboard" />;
if (!highlighter) {
return (
<div style={tw`relative mt-2`} className="readme-code-block">
<pre className="shiki">
<code>{code}</code>
</pre>
{copyButton}
</div>
);
}
return (
<div style={tw`relative mt-2`} className="readme-code-block">
{highlighter}
{copyButton}
</div>
);
}