nodebb-plugin-markdown 11.1.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -15
- package/package.json +1 -1
- package/public/js/admin.js +0 -1
- package/public/js/client.js +23 -7
- package/public/templates/admin/plugins/markdown.tpl +3 -23
package/index.js
CHANGED
|
@@ -44,7 +44,7 @@ const Markdown = {
|
|
|
44
44
|
},
|
|
45
45
|
|
|
46
46
|
getConfig: async (config) => {
|
|
47
|
-
let { defaultHighlightLanguage, highlightTheme, hljsLanguages } = await meta.settings.get('markdown');
|
|
47
|
+
let { defaultHighlightLanguage, highlightTheme, hljsLanguages, highlightLinesLanguageList } = await meta.settings.get('markdown');
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
hljsLanguages = JSON.parse(hljsLanguages);
|
|
@@ -54,7 +54,7 @@ const Markdown = {
|
|
|
54
54
|
|
|
55
55
|
config.markdown = {
|
|
56
56
|
highlight: Markdown.highlight ? 1 : 0,
|
|
57
|
-
highlightLinesLanguageList
|
|
57
|
+
highlightLinesLanguageList,
|
|
58
58
|
hljsLanguages,
|
|
59
59
|
theme: highlightTheme || 'default.css',
|
|
60
60
|
defaultHighlightLanguage: defaultHighlightLanguage || '',
|
|
@@ -86,7 +86,6 @@ const Markdown = {
|
|
|
86
86
|
|
|
87
87
|
langPrefix: 'language-',
|
|
88
88
|
highlight: true,
|
|
89
|
-
highlightLinesLanguageList: [],
|
|
90
89
|
highlightTheme: 'default.css',
|
|
91
90
|
|
|
92
91
|
probe: true,
|
|
@@ -102,7 +101,7 @@ const Markdown = {
|
|
|
102
101
|
checkboxes: true,
|
|
103
102
|
multimdTables: true,
|
|
104
103
|
};
|
|
105
|
-
const notCheckboxes = ['langPrefix', 'highlightTheme', '
|
|
104
|
+
const notCheckboxes = ['langPrefix', 'highlightTheme', 'probeCacheSize'];
|
|
106
105
|
|
|
107
106
|
meta.settings.get('markdown', (err, options) => {
|
|
108
107
|
if (err) {
|
|
@@ -123,17 +122,6 @@ const Markdown = {
|
|
|
123
122
|
_self.highlight = _self.config.highlight;
|
|
124
123
|
delete _self.config.highlight;
|
|
125
124
|
|
|
126
|
-
if (typeof _self.config.highlightLinesLanguageList === 'string') {
|
|
127
|
-
try {
|
|
128
|
-
_self.config.highlightLinesLanguageList = JSON.parse(_self.config.highlightLinesLanguageList);
|
|
129
|
-
} catch (e) {
|
|
130
|
-
winston.warn('[plugins/markdown] Invalid config for highlightLinesLanguageList, blanking.');
|
|
131
|
-
_self.config.highlightLinesLanguageList = [];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
_self.config.highlightLinesLanguageList = _self.config.highlightLinesLanguageList.join(',').split(',');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
125
|
parser = new MarkdownIt(_self.config);
|
|
138
126
|
|
|
139
127
|
Markdown.updateParserRules(parser);
|
package/package.json
CHANGED
package/public/js/admin.js
CHANGED
package/public/js/client.js
CHANGED
|
@@ -243,6 +243,7 @@
|
|
|
243
243
|
console.debug('[plugin/markdown] Initializing highlight.js');
|
|
244
244
|
let hljs;
|
|
245
245
|
let list;
|
|
246
|
+
let aliasMap = new Map();
|
|
246
247
|
switch(true) {
|
|
247
248
|
case config.markdown.hljsLanguages.includes('common'): {
|
|
248
249
|
({ default: hljs} = await import(`highlight.js/lib/common`));
|
|
@@ -261,6 +262,7 @@
|
|
|
261
262
|
list = 'core';
|
|
262
263
|
}
|
|
263
264
|
}
|
|
265
|
+
console.debug(`[plugins/markdown] Loaded ${list} hljs library`);
|
|
264
266
|
|
|
265
267
|
if (list !== 'all') {
|
|
266
268
|
await Promise.all(config.markdown.hljsLanguages.map(async (language) => {
|
|
@@ -274,6 +276,18 @@
|
|
|
274
276
|
}));
|
|
275
277
|
}
|
|
276
278
|
|
|
279
|
+
// Build alias set
|
|
280
|
+
hljs.listLanguages().forEach((language) => {
|
|
281
|
+
const { aliases } = hljs.getLanguage(language);
|
|
282
|
+
if (aliases && Array.isArray(aliases)) {
|
|
283
|
+
aliases.forEach((alias) => {
|
|
284
|
+
aliasMap.set(alias, language);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
aliasMap.set(language, language);
|
|
289
|
+
});
|
|
290
|
+
|
|
277
291
|
console.debug(`[plugins/markdown] Loading support for line numbers`);
|
|
278
292
|
window.hljs = hljs;
|
|
279
293
|
require('highlightjs-line-numbers.js');
|
|
@@ -289,14 +303,16 @@
|
|
|
289
303
|
window.hljs.highlightElement(block);
|
|
290
304
|
|
|
291
305
|
// Check detected language against whitelist and add lines if enabled
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
const classIterator = block.classList.values();
|
|
307
|
+
for(className of classIterator) {
|
|
308
|
+
if (className.startsWith('language-')) {
|
|
309
|
+
const language = className.split('-')[1];
|
|
310
|
+
if (aliasMap.has(language) && config.markdown.highlightLinesLanguageList.includes(aliasMap.get(language))) {
|
|
311
|
+
$(block).attr('data-lines', 1);
|
|
312
|
+
window.hljs.lineNumbersBlock(block);
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
295
315
|
}
|
|
296
|
-
return config.markdown.highlightLinesLanguageList.includes(className) || config.markdown.highlightLinesLanguageList.includes(className);
|
|
297
|
-
}).some(Boolean)) {
|
|
298
|
-
$(block).attr('data-lines', 1);
|
|
299
|
-
window.hljs.lineNumbersBlock(block);
|
|
300
316
|
}
|
|
301
317
|
});
|
|
302
318
|
}
|
|
@@ -131,29 +131,9 @@
|
|
|
131
131
|
Enable line numbers for the following languages
|
|
132
132
|
</label>
|
|
133
133
|
<select class="form-select" multiple="true" name="highlightLinesLanguageList" id="highlightLinesLanguageList" size="20">
|
|
134
|
-
|
|
135
|
-
<option value="
|
|
136
|
-
|
|
137
|
-
<option value="cpp,c,cc,h,c++,h++,hpp">C++</option>
|
|
138
|
-
<option value="css">CSS</option>
|
|
139
|
-
<option value="coffeescript,coffee,cson,iced">CoffeeScript</option>
|
|
140
|
-
<option value="diff,patch">Diff</option>
|
|
141
|
-
<option value="xml,html,xhtml,rss,atom,xjb,xsd,xsl,plist">HTML</option>
|
|
142
|
-
<option value="http,https">HTTP</option>
|
|
143
|
-
<option value="ini,toml">Ini</option>
|
|
144
|
-
<option value="json">JSON</option>
|
|
145
|
-
<option value="java">Java</option>
|
|
146
|
-
<option value="javascript,js,jsx">Javascript</option>
|
|
147
|
-
<option value="makefile,mk,mak">Makefile</option>
|
|
148
|
-
<option value="markdown,md,mkdown,mkd">Markdown</option>
|
|
149
|
-
<option value="nginx,nginxconf">Nginx</option>
|
|
150
|
-
<option value="objectivec,objc,obj-c">Objective C</option>
|
|
151
|
-
<option value="php,php3,php4,php5,php6">PHP</option>
|
|
152
|
-
<option value="perl,pl,pm">Perl</option>
|
|
153
|
-
<option value="python,py,gyp">Python</option>
|
|
154
|
-
<option value="ruby,rb,gemspec,podspec,thor,irb">Ruby</option>
|
|
155
|
-
<option value="sql">SQL</option>
|
|
156
|
-
<option value="shell,console">Shell</option>
|
|
134
|
+
{{{ each hljsLanguages }}}
|
|
135
|
+
<option value="{@value}">{@value}</option>
|
|
136
|
+
{{{ end }}}
|
|
157
137
|
</select>
|
|
158
138
|
<p class="form-text">
|
|
159
139
|
You can use <code>ctrl</code> and <code>shift</code> to select/deselect multiple
|