MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / highlight

Function highlight

webapp/_webapp/src/libs/code-plugin.ts:66–96  ·  view source on GitHub ↗
({ code: src, language, themes }: { code: string; language: string; themes: any }, cb?: Callback)

Source from the content-addressed store, hash-verified

64 },
65 // eslint-disable-next-line @typescript-eslint/no-explicit-any
66 highlight({ code: src, language, themes }: { code: string; language: string; themes: any }, cb?: Callback) {
67 const lang = SUPPORTED.has(language.trim().toLowerCase()) ? language.trim().toLowerCase() : "text";
68 const names: [string, string] = [themeName(themes[0]), themeName(themes[1])];
69 // eslint-disable-next-line @typescript-eslint/no-explicit-any
70 const key = cacheKey(src, lang, names as any);
71
72 if (cache.has(key)) return cache.get(key);
73
74 if (cb) {
75 if (!pending.has(key)) pending.set(key, new Set<Callback>());
76 pending.get(key)!.add(cb);
77 }
78
79 highlighterPromise.then((h) => {
80 const tokens = h.codeToTokens(src, {
81 lang: h.getLoadedLanguages().includes(lang) ? lang : "text",
82 themes: { light: names[0] as string, dark: names[1] as string },
83 });
84 cache.set(key, tokens);
85 const waiters = pending.get(key);
86 if (waiters) {
87 for (const fn of waiters) fn(tokens);
88 pending.delete(key);
89 }
90 }).catch((e) => {
91 console.error("[code-plugin] highlight failed:", e);
92 pending.delete(key);
93 });
94
95 return null;
96 },
97};
98
99// eslint-disable-next-line @typescript-eslint/no-explicit-any

Callers

nothing calls this directly

Calls 6

themeNameFunction · 0.85
cacheKeyFunction · 0.85
fnFunction · 0.85
deleteMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected