nodebb-plugin-mentions 4.6.0 → 4.6.1

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.
Files changed (2) hide show
  1. package/library.js +29 -24
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -37,6 +37,7 @@ const parts = {
37
37
  };
38
38
  const regex = RegExp(`${parts.before}${parts.main}`, 'gu');
39
39
  const isLatinMention = /@[\w\d\-_.@]+$/;
40
+ const hasAnchors = /<a.*>.*<\/a>/i;
40
41
 
41
42
  const Mentions = module.exports;
42
43
 
@@ -356,31 +357,35 @@ async function getMatches(content, isMarkdown = false) {
356
357
  }
357
358
  });
358
359
 
359
- const $ = cheerio.load(splitContent.join(''));
360
- const anchors = $('a');
361
- const urls = new Set();
362
- Array.from(anchors).forEach((anchor) => {
363
- const text = $(anchor).prop('innerText');
364
- const match = text.match(regex);
365
- if (match) {
366
- urls.add($(anchor).attr('href'));
367
- }
368
- });
369
-
370
- // Filter out urls that don't backreference to a remote id
371
- const backrefs = await db.getObjectFields('remoteUrl:uid', Array.from(urls));
372
- const urlAsIdExists = await db.isSortedSetMembers('usersRemote:lastCrawled', Array.from(urls));
360
+ const joined = splitContent.join('');
361
+ const parseAnchors = joined.match(hasAnchors);
373
362
  const urlMap = new Map();
374
- Array.from(urls).map(async (url, index) => {
375
- if (backrefs[url] || urlAsIdExists[index]) {
376
- urlMap.set(url, backrefs[url] || url);
377
- }
378
- });
379
- let slugs = await User.getUsersFields(Array.from(urlMap.values()), ['userslug']);
380
- slugs = slugs.map(({ userslug }) => userslug);
381
- Array.from(urlMap.keys()).forEach((url, idx) => {
382
- urlMap.set(url, `/user/${encodeURIComponent(slugs[idx])}`);
383
- });
363
+ if (!isMarkdown && parseAnchors) {
364
+ const $ = cheerio.load(splitContent.join(''));
365
+ const anchors = $('a');
366
+ const urls = new Set();
367
+ Array.from(anchors).forEach((anchor) => {
368
+ const text = $(anchor).prop('innerText');
369
+ const match = text.match(regex);
370
+ if (match) {
371
+ urls.add($(anchor).attr('href'));
372
+ }
373
+ });
374
+
375
+ // Filter out urls that don't backreference to a remote id
376
+ const backrefs = await db.getObjectFields('remoteUrl:uid', Array.from(urls));
377
+ const urlAsIdExists = await db.isSortedSetMembers('usersRemote:lastCrawled', Array.from(urls));
378
+ Array.from(urls).map(async (url, index) => {
379
+ if (backrefs[url] || urlAsIdExists[index]) {
380
+ urlMap.set(url, backrefs[url] || url);
381
+ }
382
+ });
383
+ let slugs = await User.getUsersFields(Array.from(urlMap.values()), ['userslug']);
384
+ slugs = slugs.map(({ userslug }) => userslug);
385
+ Array.from(urlMap.keys()).forEach((url, idx) => {
386
+ urlMap.set(url, `/user/${encodeURIComponent(slugs[idx])}`);
387
+ });
388
+ }
384
389
 
385
390
  return { splitContent, matches, urlMap };
386
391
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-mentions",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
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": {