MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / useHighlighted

Function useHighlighted

packages/react/src/components/code-block.tsx:66–79  ·  view source on GitHub ↗
(code: string, lang: string, theme?: ShikiThemeProp)

Source from the content-addressed store, hash-verified

64// ---------------------------------------------------------------------------
65
66function 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

Callers 1

CodeBlockFunction · 0.85

Calls 4

resolveLangFunction · 0.90
ensureLangFunction · 0.90
getHighlighterFunction · 0.90
dualThemeOptionsFunction · 0.90

Tested by

no test coverage detected