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

Create explicit rawInputReplacement function for userMentions #687

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,12 @@ describe('when should keep raw input flag is enabled', () => {
const resultString = '<a href="mailto:[email protected]" data-raw-href="mailto:[email protected]" data-link-variant="labeled"><strong>mail</strong></a>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});

test('user mention from phone number', () => {
const testString = '@+1234567890';
const resultString = '<mention-user>@+1234567890</mention-user>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
});
});

Expand Down
6 changes: 6 additions & 0 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ export default class ExpensiMark {
const phoneRegex = new RegExp(`^@${Constants.CONST.REG_EXP.PHONE_PART}$`);
return `${g1}<mention-user>${g2}${phoneRegex.test(g2) ? `@${Constants.CONST.SMS.DOMAIN}` : ''}</mention-user>`;
},
rawInputReplacement: (match, g1, g2) => {
if (!Str.isValidMention(match)) {
return match;
}
return `${g1}<mention-user>${g2}</mention-user>`;
},
},

{
Expand Down
Loading