nodebb-plugin-markdown 12.2.6 → 12.2.7

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
@@ -372,34 +372,25 @@ const Markdown = {
372
372
  };
373
373
 
374
374
  parser.renderer.rules.link_open = function (tokens, idx, options, env, self) {
375
- // Add target="_blank" to all links
376
- const targetIdx = tokens[idx].attrIndex('target');
377
- let relIdx = tokens[idx].attrIndex('rel');
378
- const hrefIdx = tokens[idx].attrIndex('href');
375
+ const attributes = new Map(tokens[idx].attrs);
379
376
 
380
- if (Markdown.isExternalLink(tokens[idx].attrs[hrefIdx][1])) {
377
+ if (attributes.has('href') && Markdown.isExternalLink(attributes.get('href'))) {
378
+ const rel = [];
381
379
  if (Markdown.config.externalBlank) {
382
- if (targetIdx < 0) {
383
- tokens[idx].attrPush(['target', '_blank']);
384
- } else {
385
- tokens[idx].attrs[targetIdx][1] = '_blank';
386
- }
387
-
388
- if (relIdx < 0) {
389
- tokens[idx].attrPush(['rel', 'noopener noreferrer']);
390
- relIdx = tokens[idx].attrIndex('rel');
391
- } else {
392
- tokens[idx].attrs[relIdx][1] = 'noopener noreferrer';
393
- }
380
+ attributes.set('target', '_blank');
381
+ rel.push('noopener', 'noreferrer');
394
382
  }
395
383
 
396
384
  if (Markdown.config.nofollow) {
397
- if (relIdx < 0) {
398
- tokens[idx].attrPush(['rel', 'nofollow ugc']);
399
- } else {
400
- tokens[idx].attrs[relIdx][1] += ' nofollow ugc';
401
- }
385
+ rel.push('nofollow', 'ugc');
402
386
  }
387
+
388
+ attributes.set('rel', rel.join(' '));
389
+ }
390
+
391
+ // Clearly indicate hidden links
392
+ if (tokens[idx + 1].type === 'link_close') {
393
+ attributes.set('class', String(`${attributes.get('class') || ''} plugin-markdown-hidden-link small link-danger`).trim());
403
394
  }
404
395
 
405
396
  if (!Markdown.config.allowRTLO) {
@@ -410,6 +401,7 @@ const Markdown = {
410
401
  }
411
402
  }
412
403
 
404
+ tokens[idx].attrs = Array.from(attributes);
413
405
  return renderLink(tokens, idx, options, env, self);
414
406
  };
415
407
 
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "12.2.6",
3
+ "version": "12.2.7",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "nodebb-plugin-markdown",
9
- "version": "12.2.6",
9
+ "version": "12.2.7",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "highlight.js": "11.4.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-markdown",
3
- "version": "12.2.6",
3
+ "version": "12.2.7",
4
4
  "description": "A Markdown parser for NodeBB",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -62,4 +62,13 @@
62
62
  }
63
63
  }
64
64
  }
65
+ }
66
+
67
+ a.plugin-markdown-hidden-link {
68
+ &::before {
69
+ content: 'hidden link';
70
+ border: 1px dashed $danger;
71
+ padding: .25rem;
72
+ border-radius: var(--bs-border-radius) !important;
73
+ }
65
74
  }