CodeBlock() — supabase Function Reference
Architecture documentation for the CodeBlock() function in CodeBlock.tsx from the supabase codebase.
Entity Profile
Dependency Diagram
graph TD 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de["CodeBlock()"] ec381ca3_a0ca_03ae_250e_63f4ece7f726["extractCode()"] 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de -->|calls| ec381ca3_a0ca_03ae_250e_63f4ece7f726 845600f7_3dab_ff30_03be_154874a8bf7e["tryToBundledLanguage()"] 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de -->|calls| 845600f7_3dab_ff30_03be_154874a8bf7e de3be49a_2a73_b17d_6194_ac4320ac077d["extractLang()"] 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de -->|calls| de3be49a_2a73_b17d_6194_ac4320ac077d 8bc3fa56_c62b_7b43_b1be_5f522fd0a4f7["annotationsByLine()"] 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de -->|calls| 8bc3fa56_c62b_7b43_b1be_5f522fd0a4f7 style 816ab8fd_5aaa_f5ee_1dd8_0a70d0a7f3de fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/docs/features/ui/CodeBlock/CodeBlock.tsx lines 22–113
export async function CodeBlock({
className,
lang: langSetting,
lineNumbers = true,
contents,
children,
skipTypeGeneration,
}: PropsWithChildren<{
className?: string
lang?: string
lineNumbers?: boolean
contents?: string
skipTypeGeneration?: boolean
}>) {
let code = (contents || extractCode(children)).trim()
const lang = tryToBundledLanguage(langSetting || '') || extractLang(children)
let twoslashed = null as null | Map<number, Map<number, Array<NodeHover>>>
if (!skipTypeGeneration && lang && TWOSLASHABLE_LANGS.includes(lang)) {
try {
const { code: editedCode, nodes } = twoslasher(code)
const hoverNodes: Array<NodeHover> = nodes.filter((node) => node.type === 'hover')
twoslashed = annotationsByLine(hoverNodes)
code = editedCode
} catch (_err) {
// Silently ignore, if imports aren't defined type compilation fails
// Uncomment lines below to debug in dev
// console.log('\n==========CODE==========\n')
// console.log(code)
// console.error(_err.recommendation)
}
}
const { tokens } = highlighter.codeToTokens(code, {
lang: lang || undefined,
theme: 'Supabase Theme',
})
return (
<div
className={cn(
'shiki',
'group',
'relative',
'not-prose',
'w-full overflow-x-auto',
'border border-default rounded-lg',
'bg-200',
'text-sm',
className
)}
>
<pre>
<code className={lineNumbers ? 'grid grid-cols-[auto_1fr]' : ''}>
{lineNumbers ? (
<>
{tokens.map((line, idx) => (
<Fragment key={idx}>
<div
className={cn(
'select-none text-right text-muted bg-control px-2 min-h-5 leading-5',
idx === 0 && 'pt-6',
idx === tokens.length - 1 && 'pb-6'
)}
>
{idx + 1}
</div>
<div
className={cn(
'code-content min-h-5 leading-5 pl-6 pr-6',
idx === 0 && 'pt-6',
idx === tokens.length - 1 && 'pb-6'
)}
>
<CodeLine tokens={line} twoslash={twoslashed?.get(idx)} />
</div>
</Fragment>
))}
</>
) : (
<div className="code-content p-6">
{tokens.map((line, idx) => (
<CodeLine key={idx} tokens={line} twoslash={twoslashed?.get(idx)} />
))}
</div>
)}
</code>
</pre>
<CodeBlockControls content={code.trim()} />
</div>
)
}
Domain
Subdomains
Source
Frequently Asked Questions
What does CodeBlock() do?
CodeBlock() is a function in the supabase codebase.
What does CodeBlock() call?
CodeBlock() calls 4 function(s): annotationsByLine, extractCode, extractLang, tryToBundledLanguage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free