(plugin: LSPPlugin, code: MarkedString)
| 276 | } |
| 277 | |
| 278 | function 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 | |
| 314 | function renderTooltipContent( |
| 315 | plugin: LSPPlugin, |
no test coverage detected