nodebb-plugin-markdown 13.2.4 → 13.2.5

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
@@ -4,13 +4,13 @@ const MarkdownIt = require('markdown-it');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
 
7
- const nconf = require.main.require('nconf');
8
- const winston = require.main.require('winston');
9
- const meta = require.main.require('./src/meta');
10
- const activitypub = require.main.require('./src/activitypub');
11
- const plugins = require.main.require('./src/plugins');
7
+ const nconf = nodebb.require('nconf');
8
+ const winston = nodebb.require('winston');
9
+ const meta = nodebb.require('./src/meta');
10
+ const activitypub = nodebb.require('./src/activitypub');
11
+ const plugins = nodebb.require('./src/plugins');
12
12
 
13
- const SocketPlugins = require.main.require('./src/socket.io/plugins');
13
+ const SocketPlugins = nodebb.require('./src/socket.io/plugins');
14
14
  SocketPlugins.markdown = require('./websockets');
15
15
 
16
16
  let parser;
@@ -21,8 +21,8 @@ const Markdown = {
21
21
  app = params.app;
22
22
  const { router } = params;
23
23
  const controllers = require('./lib/controllers');
24
- const hostMiddleware = require.main.require('./src/middleware');
25
- const routeHelpers = require.main.require('./src/routes/helpers');
24
+ const hostMiddleware = nodebb.require('./src/middleware');
25
+ const routeHelpers = nodebb.require('./src/routes/helpers');
26
26
  const middlewares = [
27
27
  hostMiddleware.maintenanceMode, hostMiddleware.registrationComplete, hostMiddleware.pluginHooks,
28
28
  ];
@@ -3,12 +3,16 @@
3
3
  const path = require('path');
4
4
 
5
5
  const parent = module.parent.exports;
6
- const posts = require.main.require('./src/posts');
7
- const file = require.main.require('./src/file');
8
- const Controllers = {};
6
+ const posts = nodebb.require('./src/posts');
7
+ const file = nodebb.require('./src/file');
8
+ const { paths } = nodebb.require('./src/constants');
9
+
10
+ const Controllers = module.exports;
9
11
 
10
12
  Controllers.renderAdmin = async function renderAdmin(req, res) {
11
- let hljsLanguages = await file.walk(path.resolve(require.main.path, 'node_modules/highlight.js/lib/languages'));
13
+ let hljsLanguages = await file.walk(
14
+ path.resolve(paths.nodeModules, 'highlight.js/lib/languages')
15
+ );
12
16
  hljsLanguages = hljsLanguages.map(language => path.basename(language, '.js')).filter(language => !language.endsWith('.js'));
13
17
 
14
18
  res.render('admin/plugins/markdown', {
@@ -36,5 +40,3 @@ Controllers.retrieveRaw = function retrieveRaw(req, res, next) {
36
40
  });
37
41
  });
38
42
  };
39
-
40
- module.exports = Controllers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "13.2.4",
3
+ "version": "13.2.5",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -39,14 +39,13 @@
39
39
  "markdown-it-multimd-table": "^4.0.1"
40
40
  },
41
41
  "nbbpm": {
42
- "compatibility": "^4.1.0"
42
+ "compatibility": "^4.12.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@commitlint/cli": "^19.8.0",
46
46
  "@commitlint/config-angular": "16.2.1",
47
- "eslint": "^9.25.1",
48
- "eslint-config-nodebb": "^1.1.4",
49
- "eslint-plugin-import": "^2.31.0",
47
+ "@eslint/js": "^10.0.1",
48
+ "eslint-config-nodebb": "^2.0.2",
50
49
  "husky": "7.0.4",
51
50
  "lint-staged": "12.3.5"
52
51
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  define('admin/plugins/markdown', ['settings'], function (Settings) {
4
- var Markdown = {};
4
+ const Markdown = {};
5
5
 
6
6
  Markdown.init = function () {
7
7
  Settings.load('markdown', $('.markdown-settings'), function (err, settings) {
@@ -9,7 +9,7 @@ define('admin/plugins/markdown', ['settings'], function (Settings) {
9
9
  settings = {};
10
10
  }
11
11
 
12
- var defaults = {
12
+ const defaults = {
13
13
  html: false,
14
14
 
15
15
  langPrefix: 'language-',
@@ -38,7 +38,7 @@
38
38
  }
39
39
 
40
40
  $(window).on('action:composer.enhanced', function (evt, data) {
41
- var textareaEl = data.postContainer.find('textarea');
41
+ const textareaEl = data.postContainer.find('textarea');
42
42
  markdown.capturePaste(textareaEl);
43
43
  markdown.prepareFormattingTools();
44
44
  });
@@ -2,11 +2,11 @@
2
2
 
3
3
  export function capturePaste(targetEl) {
4
4
  targetEl.on('paste', function (e) {
5
- var triggers = [/^>\s*/, /^\s*\*\s+/, /^\s*\d+\.\s+/, /^\s{4,}/];
6
- var start = e.target.selectionStart;
7
- var line = getLine(targetEl.val(), start);
5
+ const triggers = [/^>\s*/, /^\s*\*\s+/, /^\s*\d+\.\s+/, /^\s{4,}/];
6
+ const start = e.target.selectionStart;
7
+ const line = getLine(targetEl.val(), start);
8
8
 
9
- var trigger = triggers.reduce(function (regexp, cur) {
9
+ const trigger = triggers.reduce(function (regexp, cur) {
10
10
  if (regexp) {
11
11
  return regexp;
12
12
  }
@@ -14,15 +14,15 @@ export function capturePaste(targetEl) {
14
14
  return cur.test(line) ? cur : false;
15
15
  }, false);
16
16
 
17
- var prefix = line.match(trigger);
17
+ let prefix = line.match(trigger);
18
18
  if (prefix) {
19
19
  prefix = prefix.shift();
20
20
 
21
- var payload = e.originalEvent.clipboardData.getData('text');
22
- var fixed = payload.replace(/^/gm, prefix).slice(prefix.length);
21
+ const payload = e.originalEvent.clipboardData.getData('text');
22
+ const fixed = payload.replace(/^/gm, prefix).slice(prefix.length);
23
23
 
24
24
  setTimeout(function () {
25
- var replacement = targetEl.val().slice(0, start) + fixed + targetEl.val().slice(start + payload.length);
25
+ const replacement = targetEl.val().slice(0, start) + fixed + targetEl.val().slice(start + payload.length);
26
26
  targetEl.val(replacement);
27
27
  }, 0);
28
28
  }
@@ -30,7 +30,7 @@ export function capturePaste(targetEl) {
30
30
 
31
31
  function getLine(text, selectionStart) {
32
32
  // Break apart into lines, return the line the cursor is in
33
- var lines = text.split('\n');
33
+ const lines = text.split('\n');
34
34
 
35
35
  return lines.reduce(function (memo, cur) {
36
36
  if (typeof memo !== 'number') {
@@ -77,7 +77,7 @@ export function prepareFormattingTools() {
77
77
 
78
78
  formatting.addButtonDispatch('bold', function (textarea, selectionStart, selectionEnd) {
79
79
  if (selectionStart === selectionEnd) {
80
- var block = controls.getBlockData(textarea, '**', selectionStart);
80
+ const block = controls.getBlockData(textarea, '**', selectionStart);
81
81
 
82
82
  if (block.in && block.atEnd) {
83
83
  // At end of bolded string, move cursor past delimiters
@@ -89,7 +89,7 @@ export function prepareFormattingTools() {
89
89
  );
90
90
  }
91
91
  } else {
92
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '**');
92
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '**');
93
93
  controls.updateTextareaSelection(
94
94
  textarea, selectionStart + 2 + wrapDelta[0], selectionEnd + 2 - wrapDelta[1]
95
95
  );
@@ -98,7 +98,7 @@ export function prepareFormattingTools() {
98
98
 
99
99
  formatting.addButtonDispatch('italic', function (textarea, selectionStart, selectionEnd) {
100
100
  if (selectionStart === selectionEnd) {
101
- var block = controls.getBlockData(textarea, '*', selectionStart);
101
+ const block = controls.getBlockData(textarea, '*', selectionStart);
102
102
 
103
103
  if (block.in && block.atEnd) {
104
104
  // At end of italicised string, move cursor past delimiters
@@ -110,7 +110,7 @@ export function prepareFormattingTools() {
110
110
  );
111
111
  }
112
112
  } else {
113
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '*');
113
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '*');
114
114
  controls.updateTextareaSelection(
115
115
  textarea, selectionStart + 1 + wrapDelta[0], selectionEnd + 1 - wrapDelta[1]
116
116
  );
@@ -143,7 +143,7 @@ export function prepareFormattingTools() {
143
143
 
144
144
  formatting.addButtonDispatch('strikethrough', function (textarea, selectionStart, selectionEnd) {
145
145
  if (selectionStart === selectionEnd) {
146
- var block = controls.getBlockData(textarea, '~~', selectionStart);
146
+ const block = controls.getBlockData(textarea, '~~', selectionStart);
147
147
 
148
148
  if (block.in && block.atEnd) {
149
149
  // At end of bolded string, move cursor past delimiters
@@ -155,7 +155,7 @@ export function prepareFormattingTools() {
155
155
  );
156
156
  }
157
157
  } else {
158
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '~~', '~~');
158
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '~~', '~~');
159
159
  controls.updateTextareaSelection(
160
160
  textarea, selectionStart + 2 + wrapDelta[0], selectionEnd + 2 - wrapDelta[1]
161
161
  );
@@ -169,7 +169,7 @@ export function prepareFormattingTools() {
169
169
  textarea, selectionStart + 4, selectionEnd + strings['code-text'].length + 4
170
170
  );
171
171
  } else {
172
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '```\n', '\n```');
172
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '```\n', '\n```');
173
173
  controls.updateTextareaSelection(
174
174
  textarea, selectionStart + 4 + wrapDelta[0], selectionEnd + 4 - wrapDelta[1]
175
175
  );
@@ -185,7 +185,7 @@ export function prepareFormattingTools() {
185
185
  selectionEnd + strings['link-text'].length + strings['link-url'].length + 3
186
186
  );
187
187
  } else {
188
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '[', '](' + strings['link-url'] + ')');
188
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '[', '](' + strings['link-url'] + ')');
189
189
  controls.updateTextareaSelection(
190
190
  textarea, selectionEnd + 3 - wrapDelta[1], selectionEnd + strings['link-url'].length + 3 - wrapDelta[1]
191
191
  );
@@ -201,7 +201,7 @@ export function prepareFormattingTools() {
201
201
  selectionEnd + strings['picture-text'].length + strings['picture-url'].length + 4
202
202
  );
203
203
  } else {
204
- var wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '![', '](' + strings['picture-url'] + ')');
204
+ const wrapDelta = controls.wrapSelectionInTextareaWith(textarea, '![', '](' + strings['picture-url'] + ')');
205
205
  controls.updateTextareaSelection(
206
206
  textarea, selectionEnd + 4 - wrapDelta[1], selectionEnd + strings['picture-url'].length + 4 - wrapDelta[1]
207
207
  );
@@ -248,8 +248,8 @@ export function enhanceCheckbox(ev, data) {
248
248
  data.posts = [data.post];
249
249
  }
250
250
 
251
- var disable;
252
- var checkboxEls;
251
+ let disable;
252
+ let checkboxEls;
253
253
  data.posts.forEach(function (post) {
254
254
  disable = !post.display_edit_tools;
255
255
  checkboxEls = $('.posts li[data-pid="' + post.pid + '"] .content div.plugin-markdown input[type="checkbox"]');
@@ -261,9 +261,9 @@ export function enhanceCheckbox(ev, data) {
261
261
  }
262
262
 
263
263
  // Otherwise, edit the post to reflect state change
264
- var _this = this;
265
- var pid = $(this).parents('li[data-pid]').attr('data-pid');
266
- var index = $(this).parents('.content').find('input[type="checkbox"]').toArray()
264
+ const _this = this;
265
+ const pid = $(this).parents('li[data-pid]').attr('data-pid');
266
+ const index = $(this).parents('.content').find('input[type="checkbox"]').toArray()
267
267
  .reduce(function (memo, cur, index) {
268
268
  if (cur === _this) {
269
269
  memo = index;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const meta = require.main.require('./src/meta');
3
+ const meta = nodebb.require('./src/meta');
4
4
  const markdown = require('..');
5
5
 
6
6
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const meta = require.main.require('./src/meta');
3
+ const meta = nodebb.require('./src/meta');
4
4
 
5
5
  module.exports = {
6
6
  name: 'Update Markdown Theme to point to unminified file',
package/websockets.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const privileges = require.main.require('./src/privileges');
4
- const postsAPI = require.main.require('./src/api/posts');
5
- const posts = require.main.require('./src/posts');
3
+ const privileges = nodebb.require('./src/privileges');
4
+ const postsAPI = nodebb.require('./src/api/posts');
5
+ const posts = nodebb.require('./src/posts');
6
6
 
7
7
  module.exports.checkbox = {
8
8
  edit: async function (socket, data) {