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

Function highlight

packages/react/src/lib/shiki.ts:218–241  ·  view source on GitHub ↗
(options, callback)

Source from the content-addressed store, hash-verified

216 getThemes: () => [DEFAULT_LIGHT_THEME as ThemeInput, DEFAULT_DARK_THEME as ThemeInput],
217 supportsLanguage: (language: string) => isSupportedLang(language),
218 highlight(options, callback) {
219 const resolved = resolveLang(options.language);
220 const lang = resolved ?? "json";
221 // Dual-theme tokens (light-dark() colors): correct in both color
222 // schemes, so the cache never holds the wrong palette and a mid-stream
223 // scheme flip needs no re-render.
224 const key = `${lang}:${options.code.length}:${options.code.slice(0, 128)}`;
225
226 const cached = tokensCache.get(key);
227 if (cached) return cached;
228
229 const isReady = ensureLang(lang, () => {
230 // Language just loaded — highlight and notify via callback
231 const result = highlighter.codeToTokens(options.code, { lang, ...dualThemeOptions() });
232 tokensCache.set(key, result);
233 callback?.(result);
234 });
235
236 if (!isReady) return null;
237
238 const result = highlighter.codeToTokens(options.code, { lang, ...dualThemeOptions() });
239 tokensCache.set(key, result);
240 return result;
241 },
242 };
243}

Callers

nothing calls this directly

Calls 6

resolveLangFunction · 0.85
ensureLangFunction · 0.85
dualThemeOptionsFunction · 0.85
callbackFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected