MCPcopy Create free account
hub / github.com/cosscom/coss / CodeBlock

Function CodeBlock

packages/ui/src/shared/code-block.tsx:6–41  ·  view source on GitHub ↗
({
  code,
  language,
  title,
  copyButton = true,
  showLineNumbers = true,
}: {
  code: string;
  language: string;
  title?: string | undefined;
  copyButton?: boolean;
  showLineNumbers?: boolean;
})

Source from the content-addressed store, hash-verified

4import { getIconForLanguageExtension } from "@coss/ui/shared/icons";
5
6export async function CodeBlock({
7 code,
8 language,
9 title,
10 copyButton = true,
11 showLineNumbers = true,
12}: {
13 code: string;
14 language: string;
15 title?: string | undefined;
16 copyButton?: boolean;
17 showLineNumbers?: boolean;
18}) {
19 const highlightedCode = await highlightCode(code, language, {
20 showLineNumbers,
21 });
22
23 return (
24 <figure data-rehype-pretty-code-figure="">
25 {title && (
26 <figcaption
27 className="flex items-center gap-2 text-[.8125rem] text-code-foreground [&_svg]:size-4.5 [&_svg]:text-code-foreground sm:[&_svg]:size-4"
28 data-language={language}
29 data-rehype-pretty-code-title=""
30 >
31 {getIconForLanguageExtension(language)}
32 {title}
33 </figcaption>
34 )}
35 {copyButton && <CopyButton value={code} />}
36 <ScrollArea className="**:data-[slot=scroll-area-scrollbar]:data-[orientation=horizontal]:mx-2 **:data-[slot=scroll-area-scrollbar]:data-[orientation=vertical]:my-2">
37 <div dangerouslySetInnerHTML={{ __html: highlightedCode }} />
38 </ScrollArea>
39 </figure>
40 );
41}

Callers

nothing calls this directly

Calls 2

highlightCodeFunction · 0.90

Tested by

no test coverage detected