nodebb-plugin-markdown 9.0.0 → 9.0.4

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
@@ -6,6 +6,7 @@ const path = require('path');
6
6
  const url = require('url');
7
7
 
8
8
  const probe = require('probe-image-size');
9
+ const punycode = require('punycode');
9
10
 
10
11
  const nconf = require.main.require('nconf');
11
12
  const winston = require.main.require('winston');
@@ -35,19 +36,19 @@ const Markdown = {
35
36
  params.router.get('/api/post/:pid/raw', middlewares, controllers.retrieveRaw);
36
37
 
37
38
  Markdown.init();
38
- Markdown.loadThemes();
39
+ await Markdown.loadThemes();
39
40
 
40
41
  return params;
41
42
  },
42
43
 
43
44
  getConfig: async (config) => {
44
- const { defaultHighlightLanguage } = await meta.settings.get('markdown');
45
+ const { defaultHighlightLanguage, highlightTheme } = await meta.settings.get('markdown');
45
46
 
46
47
  config.markdown = {
47
48
  highlight: Markdown.highlight ? 1 : 0,
48
49
  highlightLinesLanguageList: Markdown.config.highlightLinesLanguageList,
49
- theme: Markdown.config.highlightTheme || 'default.min.css',
50
- defaultHighlightLanguage,
50
+ theme: highlightTheme || 'default.min.css',
51
+ defaultHighlightLanguage: defaultHighlightLanguage || '',
51
52
  };
52
53
 
53
54
  return config;
@@ -59,13 +60,13 @@ const Markdown = {
59
60
  hookData.links.push({
60
61
  rel: 'prefetch stylesheet',
61
62
  type: '',
62
- href: `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/${highlightTheme || 'default.min.css'}`,
63
+ href: `${nconf.get('relative_path')}/assets/plugins/nodebb-plugin-markdown/themes/${highlightTheme || 'default.min.css'}`,
63
64
  }, {
64
65
  rel: 'prefetch',
65
66
  href: `${nconf.get('relative_path')}/assets/language/${meta.config.defaultLang || 'en-GB'}/markdown.json?${meta.config['cache-buster']}`,
66
67
  }, {
67
68
  rel: 'prefetch',
68
- href: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js',
69
+ href: `${nconf.get('relative_path')}/assets/src/modules/highlight.js`,
69
70
  });
70
71
 
71
72
  return hookData;
@@ -143,22 +144,17 @@ const Markdown = {
143
144
  });
144
145
  },
145
146
 
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
- }
147
+ loadThemes: async () => {
148
+ try {
149
+ const files = await fs.promises.readdir(path.resolve(require.main.paths[0], '@highlightjs/cdn-assets/styles'));
153
150
  const isStylesheet = /\.css$/;
154
151
  Markdown.themes = files.filter(function (file) {
155
152
  return isStylesheet.test(file);
156
- }).map(function (file) {
157
- return {
158
- name: file,
159
- };
160
153
  });
161
- });
154
+ } catch (err) {
155
+ winston.error('[plugin/markdown] Could not load Markdown themes: ' + err.message);
156
+ Markdown.themes = [];
157
+ }
162
158
  },
163
159
 
164
160
  parsePost: async function (data) {
@@ -406,6 +402,11 @@ const Markdown = {
406
402
  }
407
403
  }
408
404
 
405
+ // Convert any homographs in link text to punycode
406
+ if (tokens[idx + 1] && tokens[idx + 1].type === 'text') {
407
+ tokens[idx + 1].content = punycode.toASCII(tokens[idx + 1].content);
408
+ }
409
+
409
410
  return renderLink(tokens, idx, options, env, self);
410
411
  };
411
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "9.0.0",
3
+ "version": "9.0.4",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -34,7 +34,8 @@
34
34
  "markdown-it": "^12.0.6",
35
35
  "markdown-it-checkbox": "^1.1.0",
36
36
  "markdown-it-multimd-table": "^4.0.1",
37
- "probe-image-size": "^7.2.1"
37
+ "probe-image-size": "^7.2.1",
38
+ "punycode": "^2.1.1"
38
39
  },
39
40
  "nbbpm": {
40
41
  "compatibility": "^1.17.0"
package/plugin.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "public/js/admin.js"
15
15
  ],
16
16
  "staticDirs": {
17
- "js": "public/js"
17
+ "themes": "../@highlightjs/cdn-assets/styles"
18
18
  },
19
19
  "modules": {
20
- "highlight.js": "./node_modules/@highlightjs/cdn-assets/highlight.min.js",
20
+ "highlight.js": "../@highlightjs/cdn-assets/highlight.min.js",
21
21
  "highlightjs-line-numbers.js": "./public/js/highlightjs-line-numbers.js"
22
22
  },
23
23
  "languages": "public/languages",
@@ -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
+ };