MCPcopy Create free account
hub / github.com/NodeBB/nodebb-plugin-markdown / processHighlight

Function processHighlight

public/js/markdown.js:310–351  ·  view source on GitHub ↗
(elements)

Source from the content-addressed store, hash-verified

308}
309
310async function processHighlight(elements) {
311 if (parseInt(config.markdown.highlight, 10)) {
312 const hljs = window.hljs;
313 if (!hljs) {
314 console.debug(`[plugins/markdown] Tryin to highlight without initializing hljs`);
315 return;
316 }
317
318 console.debug(`[plugins/markdown] Loading support for line numbers`);
319
320 require('highlightjs-line-numbers.js');
321
322 elements.each(function (i, block) {
323 const parentNode = $(block.parentNode);
324 if (parentNode.hasClass('markdown-highlight')) {
325 return;
326 }
327 parentNode.addClass('markdown-highlight');
328
329 // Default language if set in ACP
330 if (!Array.prototype.some.call(block.classList, (className) => className.startsWith('language-')) && config.markdown.defaultHighlightLanguage) {
331 block.classList.add(`language-${config.markdown.defaultHighlightLanguage}`);
332 }
333
334 window.hljs.highlightElement(block);
335
336 // Check detected language against whitelist and add lines if enabled
337 const classIterator = block.classList.values();
338 for (const className of classIterator) {
339 if (className.startsWith('language-')) {
340 const language = className.split('-')[1];
341 const list = config.markdown.highlightLinesLanguageList;
342 if (aliasMap.has(language) && list && list.includes(aliasMap.get(language))) {
343 $(block).attr('data-lines', 1);
344 window.hljs.lineNumbersBlock(block);
345 }
346 break;
347 }
348 }
349 });
350 }
351}

Callers 1

highlightFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…