nodebb-plugin-markdown 12.2.2 → 12.2.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
@@ -200,7 +200,7 @@ const Markdown = {
200
200
  while ((current = matcher.exec(data.postData.content)) !== null) {
201
201
  const match = current[1];
202
202
  if (match && Markdown.isExternalLink(match)) { // for security only parse external images
203
- const parsedUrl = new URL(match);
203
+ const parsedUrl = new URL(match, nconf.get('url'));
204
204
  const filename = path.basename(parsedUrl.pathname);
205
205
  const size = Markdown._externalImageCache.get(match);
206
206
 
@@ -277,6 +277,18 @@ const Markdown = {
277
277
  const formatting = [
278
278
  { name: 'bold', className: 'fa fa-bold', title: '[[modules:composer.formatting.bold]]' },
279
279
  { name: 'italic', className: 'fa fa-italic', title: '[[modules:composer.formatting.italic]]' },
280
+ {
281
+ className: 'fa fa-heading',
282
+ title: '[[modules:composer.formatting.heading]]',
283
+ dropdownItems: [
284
+ { name: 'heading1', text: '[[modules:composer.formatting.heading1]]' },
285
+ { name: 'heading2', text: '[[modules:composer.formatting.heading2]]' },
286
+ { name: 'heading3', text: '[[modules:composer.formatting.heading3]]' },
287
+ { name: 'heading4', text: '[[modules:composer.formatting.heading4]]' },
288
+ { name: 'heading5', text: '[[modules:composer.formatting.heading5]]' },
289
+ { name: 'heading6', text: '[[modules:composer.formatting.heading6]]' },
290
+ ],
291
+ },
280
292
  { name: 'list', className: 'fa fa-list-ul', title: '[[modules:composer.formatting.list]]' },
281
293
  { name: 'strikethrough', className: 'fa fa-strikethrough', title: '[[modules:composer.formatting.strikethrough]]' },
282
294
  { name: 'code', className: 'fa fa-code', title: '[[modules:composer.formatting.code]]' },
@@ -432,7 +444,7 @@ const Markdown = {
432
444
  const allowed = pathname => allowedRoots.some(root => pathname.toString().startsWith(root) || pathname.toString().startsWith(nconf.get('relative_path') + root));
433
445
 
434
446
  try {
435
- const urlObj = new URL(src);
447
+ const urlObj = new URL(src, nconf.get('url'));
436
448
  return !(urlObj.host === null && !allowed(urlObj.pathname));
437
449
  } catch (e) {
438
450
  return false;
@@ -443,11 +455,7 @@ const Markdown = {
443
455
  let urlObj;
444
456
  let baseUrlObj;
445
457
  try {
446
- if (urlString.startsWith('//')) {
447
- urlString = `${nconf.get('url_parsed').protocol}${urlString}`;
448
- }
449
-
450
- urlObj = new URL(urlString);
458
+ urlObj = new URL(urlString, nconf.get('url'));
451
459
  baseUrlObj = nconf.get('url_parsed');
452
460
  } catch (err) {
453
461
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "12.2.2",
3
+ "version": "12.2.4",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -52,6 +52,23 @@ export function prepareFormattingTools() {
52
52
  ], function (formatting, controls, translator) {
53
53
  if (formatting && controls) {
54
54
  translator.getTranslations(window.config.userLang || window.config.defaultLang, 'markdown', function (strings) {
55
+ // used for h1,h2...h6
56
+ function formatHeading(heading, textarea, selectionStart, selectionEnd) {
57
+ if (selectionStart === selectionEnd) {
58
+ controls.insertIntoTextarea(textarea, `${heading} ${strings.heading}`);
59
+
60
+ controls.updateTextareaSelection(
61
+ textarea, selectionStart + heading.length + 1, selectionStart + strings.heading.length + heading.length + 1
62
+ );
63
+ } else {
64
+ const selectedText = $(textarea).val().substring(selectionStart, selectionEnd);
65
+ const newText = `${heading} ${selectedText}`;
66
+ controls.replaceSelectionInTextareaWith(textarea, newText);
67
+ controls.updateTextareaSelection(textarea, selectionStart + (heading.length + 1), selectionEnd + (newText.length - selectedText.length));
68
+ }
69
+ }
70
+
71
+
55
72
  formatting.addButtonDispatch('bold', function (textarea, selectionStart, selectionEnd) {
56
73
  if (selectionStart === selectionEnd) {
57
74
  var block = controls.getBlockData(textarea, '**', selectionStart);
@@ -94,6 +111,12 @@ export function prepareFormattingTools() {
94
111
  }
95
112
  });
96
113
 
114
+ [1, 2, 3, 4, 5, 6].forEach((size) => {
115
+ formatting.addButtonDispatch(`heading${size}`, function (textarea, selectionStart, selectionEnd) {
116
+ formatHeading(new Array(size).fill('#').join(''), textarea, selectionStart, selectionEnd);
117
+ });
118
+ })
119
+
97
120
  formatting.addButtonDispatch('list', function (textarea, selectionStart, selectionEnd) {
98
121
  if (selectionStart === selectionEnd) {
99
122
  controls.insertIntoTextarea(textarea, '\n* ' + strings.list_item);
@@ -106,7 +129,7 @@ export function prepareFormattingTools() {
106
129
  const selectedText = $(textarea).val().substring(selectionStart, selectionEnd);
107
130
  const newText = '* ' + selectedText.split('\n').join('\n* ');
108
131
  controls.replaceSelectionInTextareaWith(textarea, newText);
109
- controls.updateTextareaSelection(textarea, selectionStart, selectionEnd + (newText.length - selectedText.length));
132
+ controls.updateTextareaSelection(textarea, selectionStart + 2, selectionEnd + (newText.length - selectedText.length));
110
133
  }
111
134
  });
112
135
 
@@ -2,6 +2,7 @@
2
2
  "bold": "bolded text",
3
3
  "italic": "italicised text",
4
4
  "list_item": "list item",
5
+ "heading": "heading",
5
6
  "strikethrough_text": "strikethrough text",
6
7
  "code_text": "code_text",
7
8
  "link_text": "link text",