Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the issue that inconsistent highlighting occurs when multiple mentions are used without spaces #594

Merged
merged 10 commits into from
Nov 19, 2023
30 changes: 30 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,36 @@ test('Test for @here mention without space or supported styling character', () =
expect(parser.replace(testString)).toBe(resultString);
});

test('Test user mention and here mention, which are concatenated without space', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use general emails, not mine 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's updated with general ones

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update Step 2 in Tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done as well

let testString = '@[email protected]@here';
let resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected][email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@here@[email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@here@[email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for mention inside link and email markdown', () => {
const testString = '[@[email protected]](expensify.com) '
+ '[_@[email protected]_](expensify.com) '
Expand Down
8 changes: 7 additions & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class ExpensiMark {
*/
{
name: 'hereMentions',
regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(?=\b)(?!(@[a-zA-Z0-9-]+?(\.[a-zA-Z]+)+)|((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
regex: /([^@*~]?)(@here)([^@*~]?)(?=\b)(?!([\w'#%+-]*@(?:[a-z\d-]+\.)+[a-z]{2,}(?:\s|$|@here))|((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match, g1, g2, g3) => {
if (!Str.isValidMention(match)) {
return match;
Expand All @@ -124,6 +124,12 @@ export default class ExpensiMark {
},
},

{
name: 'hereMentionAfterUserMentions',
regex: /(<\/mention-user>)(@here)(?=\b)/gm,
replacement: '$1<mention-here>$2</mention-here>',
},

/**
* Automatically link urls. Runs last of our linkers since we want anything manual to link before this,
* and we do not want to break emails.
Expand Down
Loading