MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / renderCode

Function renderCode

src/cm/lsp/tooltipExtensions.ts:278–312  ·  view source on GitHub ↗
(plugin: LSPPlugin, code: MarkedString)

Source from the content-addressed store, hash-verified

276}
277
278function renderCode(plugin: LSPPlugin, code: MarkedString): string {
279 const client = plugin.client as typeof plugin.client & LspClientInternals;
280
281 if (typeof code === "string") {
282 return plugin.docToHTML(code, "markdown");
283 }
284
285 const { language, value } = code;
286 let lang = client.config?.highlightLanguage?.(language || "") ?? undefined;
287
288 if (!lang) {
289 const viewLang = plugin.view.state.facet(languageFacet);
290 if (viewLang && (!language || matchingModeName(viewLang.name, language))) {
291 lang = viewLang;
292 }
293 }
294
295 if (!lang) return escapeHtml(value);
296
297 let result = "";
298 highlightCode(
299 value,
300 lang.parser.parse(value),
301 { style: (tags) => highlightingFor(plugin.view.state, tags) },
302 (text, cls) => {
303 result += cls
304 ? `<span class="${cls}">${escapeHtml(text)}</span>`
305 : escapeHtml(text);
306 },
307 () => {
308 result += "<br>";
309 },
310 );
311 return result;
312}
313
314function renderTooltipContent(
315 plugin: LSPPlugin,

Callers 1

renderTooltipContentFunction · 0.85

Calls 2

matchingModeNameFunction · 0.85
escapeHtmlFunction · 0.70

Tested by

no test coverage detected