nodebb-plugin-mentions 4.6.1 → 4.6.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/library.js +29 -24
- package/package.json +4 -6
package/library.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
const _ = require('lodash');
|
|
6
6
|
const validator = require('validator');
|
|
7
7
|
const entitiesDecode = require('html-entities').decode;
|
|
8
|
-
const cheerio = require('cheerio');
|
|
9
8
|
|
|
10
9
|
const nconf = require.main.require('nconf');
|
|
11
10
|
const winston = require.main.require('winston');
|
|
@@ -37,7 +36,7 @@ const parts = {
|
|
|
37
36
|
};
|
|
38
37
|
const regex = RegExp(`${parts.before}${parts.main}`, 'gu');
|
|
39
38
|
const isLatinMention = /@[\w\d\-_.@]+$/;
|
|
40
|
-
const
|
|
39
|
+
const anchorRegex = /<a.*?href=['"](.+?)['"].*?>(.*?)<\/a>/ig;
|
|
41
40
|
|
|
42
41
|
const Mentions = module.exports;
|
|
43
42
|
|
|
@@ -357,23 +356,24 @@ async function getMatches(content, isMarkdown = false) {
|
|
|
357
356
|
}
|
|
358
357
|
});
|
|
359
358
|
|
|
359
|
+
// Early return
|
|
360
|
+
if (isMarkdown) {
|
|
361
|
+
return { splitContent, matches, urlMap: new Map() };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Find matches via backreferenced href
|
|
360
365
|
const joined = splitContent.join('');
|
|
361
|
-
const
|
|
366
|
+
const anchors = new Set(joined.matchAll(anchorRegex));
|
|
362
367
|
const urlMap = new Map();
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const text = $(anchor).prop('innerText');
|
|
369
|
-
const match = text.match(regex);
|
|
370
|
-
if (match) {
|
|
371
|
-
urls.add($(anchor).attr('href'));
|
|
372
|
-
}
|
|
368
|
+
const urls = new Set();
|
|
369
|
+
if (!isMarkdown && anchors.size) {
|
|
370
|
+
anchors.forEach((match) => {
|
|
371
|
+
const [, url] = match;
|
|
372
|
+
urls.add(url);
|
|
373
373
|
});
|
|
374
374
|
|
|
375
375
|
// Filter out urls that don't backreference to a remote id
|
|
376
|
-
const backrefs = await db.getObjectFields('remoteUrl:uid', Array.from(urls));
|
|
376
|
+
const backrefs = urls.size ? await db.getObjectFields('remoteUrl:uid', Array.from(urls)) : {};
|
|
377
377
|
const urlAsIdExists = await db.isSortedSetMembers('usersRemote:lastCrawled', Array.from(urls));
|
|
378
378
|
Array.from(urls).map(async (url, index) => {
|
|
379
379
|
if (backrefs[url] || urlAsIdExists[index]) {
|
|
@@ -502,20 +502,25 @@ Mentions.parseRaw = async (content, type = 'default') => {
|
|
|
502
502
|
}
|
|
503
503
|
}));
|
|
504
504
|
|
|
505
|
-
|
|
505
|
+
let parsed = splitContent.join('');
|
|
506
|
+
|
|
507
|
+
// Early return if no urls to modify
|
|
508
|
+
if (!urlMap.size) {
|
|
509
|
+
return parsed;
|
|
510
|
+
}
|
|
506
511
|
|
|
507
512
|
// Modify existing anchors to local profile
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
513
|
+
const anchors = new Set(Array.from(parsed.matchAll(anchorRegex)).reverse());
|
|
514
|
+
if (!anchors.size) {
|
|
515
|
+
return parsed;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
anchors.forEach(([match, href]) => {
|
|
519
|
+
const replacement = match.replace(href, urlMap.get(href));
|
|
520
|
+
parsed = parsed.split(match).join(replacement);
|
|
516
521
|
});
|
|
517
522
|
|
|
518
|
-
return
|
|
523
|
+
return parsed;
|
|
519
524
|
};
|
|
520
525
|
|
|
521
526
|
Mentions.clean = function (input, isMarkdown, stripBlockquote, stripCode) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-mentions",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.2",
|
|
4
4
|
"description": "NodeBB Plugin that allows users to mention other users by prepending an '@' sign to their username",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"repository": {
|
|
@@ -22,16 +22,14 @@
|
|
|
22
22
|
"compatibility": "^4.0.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"cheerio": "^1.0.0-rc.12",
|
|
26
25
|
"html-entities": "^2.3.2",
|
|
27
26
|
"lodash": "4.17.21",
|
|
28
|
-
"sanitize-html": "^2.13.0",
|
|
29
27
|
"validator": "^13.0.0"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"eslint": "9.3.0",
|
|
30
|
+
"eslint": "^8.0.0",
|
|
34
31
|
"eslint-config-nodebb": "0.2.1",
|
|
35
|
-
"eslint-plugin-import": "2.29.1"
|
|
32
|
+
"eslint-plugin-import": "2.29.1",
|
|
33
|
+
"mocha": "10.4.0"
|
|
36
34
|
}
|
|
37
35
|
}
|