nodebb-plugin-markdown 9.0.1 → 9.0.2

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 CHANGED
@@ -35,18 +35,18 @@ const Markdown = {
35
35
  params.router.get('/api/post/:pid/raw', middlewares, controllers.retrieveRaw);
36
36
 
37
37
  Markdown.init();
38
- Markdown.loadThemes();
38
+ await Markdown.loadThemes();
39
39
 
40
40
  return params;
41
41
  },
42
42
 
43
43
  getConfig: async (config) => {
44
- const { defaultHighlightLanguage } = await meta.settings.get('markdown');
44
+ const { defaultHighlightLanguage, highlightTheme } = await meta.settings.get('markdown');
45
45
 
46
46
  config.markdown = {
47
47
  highlight: Markdown.highlight ? 1 : 0,
48
48
  highlightLinesLanguageList: Markdown.config.highlightLinesLanguageList,
49
- theme: Markdown.config.highlightTheme || 'default.min.css',
49
+ theme: highlightTheme || 'default.min.css',
50
50
  defaultHighlightLanguage: defaultHighlightLanguage || '',
51
51
  };
52
52
 
@@ -59,7 +59,7 @@ const Markdown = {
59
59
  hookData.links.push({
60
60
  rel: 'prefetch stylesheet',
61
61
  type: '',
62
- href: `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/${highlightTheme || 'default.min.css'}`,
62
+ href: `${nconf.get('relative_path')}/assets/plugins/nodebb-plugin-markdown/themes/${highlightTheme || 'default.min.css'}`,
63
63
  }, {
64
64
  rel: 'prefetch',
65
65
  href: `${nconf.get('relative_path')}/assets/language/${meta.config.defaultLang || 'en-GB'}/markdown.json?${meta.config['cache-buster']}`,
@@ -143,22 +143,17 @@ const Markdown = {
143
143
  });
144
144
  },
145
145
 
146
- loadThemes: function () {
147
- fs.readdir(path.resolve(__dirname, 'node_modules/@highlightjs/cdn-assets/styles'), function (err, files) {
148
- if (err) {
149
- winston.error('[plugin/markdown] Could not load Markdown themes: ' + err.message);
150
- Markdown.themes = [];
151
- return;
152
- }
146
+ loadThemes: async () => {
147
+ try {
148
+ const files = await fs.promises.readdir(path.resolve(require.main.paths[0], '@highlightjs/cdn-assets/styles'));
153
149
  const isStylesheet = /\.css$/;
154
150
  Markdown.themes = files.filter(function (file) {
155
151
  return isStylesheet.test(file);
156
- }).map(function (file) {
157
- return {
158
- name: file,
159
- };
160
152
  });
161
- });
153
+ } catch (err) {
154
+ winston.error('[plugin/markdown] Could not load Markdown themes: ' + err.message);
155
+ Markdown.themes = [];
156
+ }
162
157
  },
163
158
 
164
159
  parsePost: async function (data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
package/plugin.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "public/js/admin.js"
15
15
  ],
16
16
  "staticDirs": {
17
- "js": "public/js"
17
+ "themes": "./node_modules/@highlightjs/cdn-assets/styles"
18
18
  },
19
19
  "modules": {
20
20
  "highlight.js": "./node_modules/@highlightjs/cdn-assets/highlight.min.js",
@@ -36,5 +36,8 @@
36
36
  { "hook": "filter:config.get", "method": "getConfig" },
37
37
  { "hook": "filter:meta.getLinkTags", "method": "getLinkTags"},
38
38
  { "hook": "filter:sanitize.config", "method": "updateSanitizeConfig" }
39
+ ],
40
+ "upgrades": [
41
+ "upgrades/reset_md_hljs_theme.js"
39
42
  ]
40
43
  }
@@ -82,9 +82,9 @@
82
82
  <div class="form-group">
83
83
  <label for="highlightTheme">Use this theme for highlighted code blocks</label>
84
84
  <select class="form-control" name="highlightTheme" id="highlightTheme">
85
- <!-- BEGIN themes -->
86
- <option value="{themes.name}">{themes.name}</option>
87
- <!-- END themes -->
85
+ {{{ each themes }}}
86
+ <option value="{@value}">{@value}</option>
87
+ {{{ end }}}
88
88
  </select>
89
89
  </div>
90
90
 
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const meta = require.main.require('./src/meta');
4
+ const markdown = require('..');
5
+
6
+ module.exports = {
7
+ name: 'Reset Markdown Theme (if selected theme is not available)',
8
+ timestamp: Date.UTC(2022, 0, 31),
9
+ method: async () => {
10
+ const { highlightTheme } = await meta.settings.get('markdown');
11
+ await markdown.loadThemes();
12
+
13
+ let newTheme = highlightTheme.replace('.css', '.min.css');
14
+ if (!markdown.themes.includes(newTheme)) {
15
+ newTheme = 'default.min.css';
16
+ }
17
+
18
+ await meta.settings.setOne('markdown', 'highlightTheme', newTheme);
19
+ },
20
+ };