nodebb-plugin-mentions 4.8.10 → 4.8.11

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/LICENSE CHANGED
@@ -1,8 +1,8 @@
1
- Copyright (c) 2013-2014, Julian Lam <julian@designcreateplay.com>
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
1
+ Copyright (c) 2013-2014, Julian Lam <julian@designcreateplay.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
8
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
- # Username/Group Mentions
2
-
3
- This NodeBB plugin allows posters to reference (or *mention*) other users or groups on a NodeBB by simply
4
- precluding the `@` symbol before a username.
5
-
6
- A link is automatically added to the post.
7
-
8
- ## Installation
9
-
10
- This plugin is bundled with every NodeBB install. If not, you can install it via the Plugins page of the ACP.
11
-
12
- Alternatively,
13
-
1
+ # Username/Group Mentions
2
+
3
+ This NodeBB plugin allows posters to reference (or *mention*) other users or groups on a NodeBB by simply
4
+ precluding the `@` symbol before a username.
5
+
6
+ A link is automatically added to the post.
7
+
8
+ ## Installation
9
+
10
+ This plugin is bundled with every NodeBB install. If not, you can install it via the Plugins page of the ACP.
11
+
12
+ Alternatively,
13
+
14
14
  npm install nodebb-plugin-mentions
package/library.js CHANGED
@@ -32,7 +32,7 @@ const utility = require('./lib/utility');
32
32
 
33
33
  const parts = {
34
34
  before: '(?<=(^|\\P{L}))', // a single unicode non-letter character or start of line
35
- main: '(@[\\p{L}\\d\\-_.@]+)', // unicode letters, numbers, dashes, underscores, or periods
35
+ main: '(@[\\p{L}\\d\\-_.@]+(?<![.-]))', // unicode letters, numbers, dashes, underscores, or periods, negative lookbehind to guard against periods/dashes at end
36
36
  after: '((?=\\b)(?=[^-])|(?=[^\\p{L}\\d\\-_.@])|$)', // used to figure out where latin mentions end
37
37
  };
38
38
  const regex = RegExp(`${parts.before}${parts.main}`, 'gu');
@@ -434,6 +434,7 @@ Mentions.parseRaw = async (content, type = 'default') => {
434
434
  });
435
435
 
436
436
  // Convert matches to anchor html
437
+ let replacements = new Set();
437
438
  await Promise.all(matches.map(async (match) => {
438
439
  const slug = slugify(match.slice(1));
439
440
  match = removePunctuationSuffix(match);
@@ -475,6 +476,15 @@ Mentions.parseRaw = async (content, type = 'default') => {
475
476
  }
476
477
  }
477
478
 
479
+ replacements.add({ match, url, user, mentionType });
480
+ }
481
+ }));
482
+
483
+ replacements = Array.from(replacements)
484
+ .sort((a, b) => {
485
+ return b.user.userslug.length - a.user.userslug.length;
486
+ })
487
+ .forEach(({ match, url, user, mentionType }) => {
478
488
  const regex = isLatinMention.test(match) ?
479
489
  RegExp(`${parts.before}${match}${parts.after}`, 'gu') :
480
490
  RegExp(`${parts.before}${match}`, 'gu');
@@ -512,8 +522,7 @@ Mentions.parseRaw = async (content, type = 'default') => {
512
522
  return plain + str;
513
523
  });
514
524
  });
515
- }
516
- }));
525
+ });
517
526
 
518
527
  return splitContent.join('');
519
528
  };