MCPcopy Index your code
hub / github.com/upstash/jstack / Code

Function Code

www/src/components/mdx/code.tsx:15–68  ·  view source on GitHub ↗
({
  title,
  language,
  code,
}: {
  title?: string
  language: string
  code: string
})

Source from the content-addressed store, hash-verified

13 */
14
15export async function Code({
16 title,
17 language,
18 code,
19}: {
20 title?: string
21 language: string
22 code: string
23}) {
24 const highlightedCode = await highlightCode(code)
25
26 const Icon =
27 language === "bash"
28 ? Icons.terminal
29 : language === "ts" || language === "tsx"
30 ? Icons.typescript
31 : () => null
32
33 return (
34 <div className="border border-dark-gray rounded-md">
35 {title ? (
36 <div className="rounded-t-md flex items-center justify-between py-3 px-4 bg-zinc-950/25 border-b border-dark-gray">
37 <div className="flex items-center gap-2.5">
38 {Icon && <Icon className="grayscale size-4" />}
39 <p className="text-sm font-medium text-gray-300">{title}</p>
40 </div>
41 <CopyButton code={code} />
42 </div>
43 ) : null}
44 <ScrollArea className="">
45 <div
46 className={cn(
47 "relative py-[14px] w-full bg-[#22272e] rounded-md antialiased",
48 {
49 "rounded-t-none": Boolean(title),
50 }
51 )}
52 >
53 {!title && (
54 <div className="absolute right-2 top-2">
55 <CopyButton code={code} />
56 </div>
57 )}
58 <section
59 dangerouslySetInnerHTML={{
60 __html: highlightedCode,
61 }}
62 />
63 </div>
64 <ScrollBar orientation="horizontal" />
65 </ScrollArea>
66 </div>
67 )
68}
69
70async function highlightCode(code: string) {
71 const file = await unified()

Callers

nothing calls this directly

Calls 2

cnFunction · 0.90
highlightCodeFunction · 0.85

Tested by

no test coverage detected