-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCodeBlock.tsx
29 lines (25 loc) · 850 Bytes
/
CodeBlock.tsx
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
"use server";
import {codeToHtml, getPopoverReplacer} from "@/lib/CodeToHtml";
import {Shard} from "@/types/Shard";
import {ReactElement} from "react";
type CodeBlockProps = {
path: string,
code: string,
language: string,
shard: Shard,
popover?: boolean,
}
export async function CodeBlock({code, language, shard, path, popover = true}: CodeBlockProps): Promise<ReactElement> {
const reactElements = await codeToHtml(code, language, {
popover,
replacers: popover ? [
getPopoverReplacer(shard, language),
] : undefined,
});
return <fieldset className="relative grid gap-6 rounded-lg border m-1 text-sm">
<legend className="absolute -top-2.5 left-20 text-sm font-medium text-muted-foreground">
{path}
</legend>
{reactElements}
</fieldset>;
}