({
code,
lang = 'tsx',
compact = false,
preHighlighted = false,
...props
}: CodeBlockProps)
| 13 | const importHighlight = import('./code-block-highlighter') |
| 14 | |
| 15 | export function CodeBlock({ |
| 16 | code, |
| 17 | lang = 'tsx', |
| 18 | compact = false, |
| 19 | preHighlighted = false, |
| 20 | ...props |
| 21 | }: CodeBlockProps) { |
| 22 | const [html, setHtml] = useState<string | null>(null) |
| 23 | const { highlight, renderCodeSkeleton } = use(importHighlight) |
| 24 | useEffect(() => { |
| 25 | ;(async () => { |
| 26 | const x = preHighlighted ? code : await highlight(code, lang) |
| 27 | setHtml(x) |
| 28 | })() |
| 29 | }, [code, lang, highlight, preHighlighted]) |
| 30 | return ( |
| 31 | <FumaDocsCodeBlock |
| 32 | // @ts-expect-error |
| 33 | custom={compact ? 'compact' : undefined} |
| 34 | {...props} |
| 35 | > |
| 36 | <Pre |
| 37 | dangerouslySetInnerHTML={{ |
| 38 | __html: html ?? renderCodeSkeleton(code) |
| 39 | }} |
| 40 | /> |
| 41 | </FumaDocsCodeBlock> |
| 42 | ) |
| 43 | } |
nothing calls this directly
no test coverage detected