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

Function initHljs

public/js/client.js:5–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3(function () {
4 require(['markdown', 'components'], (markdown, components) => {
5 async function initHljs() {
6 if (window.hljs) {
7 return;
8 }
9 console.debug('[plugin/markdown] Initializing highlight.js');
10 let hljs;
11 let list;
12 if (config.markdown.hljsLanguages.includes('common')) {
13 ({ default: hljs} = await import(`highlight.js/lib/common`));
14 list = 'common';
15 } else if (config.markdown.hljsLanguages.includes('all')) {
16 ({ default: hljs} = await import(`highlight.js`));
17 list = 'all';
18 } else {
19 ({ default: hljs} = await import(`highlight.js/lib/core`));
20 list = 'core';
21 }
22
23 console.debug(`[plugins/markdown] Loaded ${list} hljs library`);
24
25 if (list !== 'all') {
26 await Promise.all(config.markdown.hljsLanguages.map(async (language) => {
27 if (['common', 'all'].includes(language)) {
28 return;
29 }
30
31 console.debug(`[plugins/markdown] Loading ${language} support`);
32 const { default: lang } = await import('../../node_modules/highlight.js/lib/languages/' + language + '.js');
33 hljs.registerLanguage(language, lang);
34 }));
35 }
36 window.hljs = hljs;
37 markdown.buildAliasMap();
38 }
39
40 $(window).on('action:composer.enhanced', function (evt, data) {
41 const textareaEl = data.postContainer.find('textarea');

Callers 1

client.jsFile · 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…