(code: string, lang: string, theme?: ShikiThemeProp)
| 64 | // --------------------------------------------------------------------------- |
| 65 | |
| 66 | function useHighlighted(code: string, lang: string, theme?: ShikiThemeProp): ReactNode | null { |
| 67 | const [, setTick] = useState(0); |
| 68 | const resolvedLang = (resolveLang(lang) ?? "json") as Parameters<typeof ensureLang>[0]; |
| 69 | |
| 70 | const isReady = ensureLang(resolvedLang, () => setTick((t) => t + 1)); |
| 71 | |
| 72 | if (!isReady) return null; |
| 73 | |
| 74 | const highlighter = getHighlighter(); |
| 75 | // Dual-theme light-dark() colors: the markup is correct in BOTH color |
| 76 | // schemes, so SSR/hydration can't paint the wrong palette first. |
| 77 | const hast = highlighter.codeToHast(code, { lang: resolvedLang, ...dualThemeOptions(theme) }); |
| 78 | return toJsxRuntime(hast, { jsx, jsxs, Fragment }); |
| 79 | } |
| 80 | |
| 81 | // --------------------------------------------------------------------------- |
| 82 | // CodeBlock |
no test coverage detected