Skip to content

Commit

Permalink
Merge pull request #687 from software-mansion-labs/@robertKozik/phone…
Browse files Browse the repository at this point in the history
…-mention-raw-input

Create explicit `rawInputReplacement` function for userMentions
  • Loading branch information
pecanoro authored Apr 25, 2024
2 parents 9a68635 + 41390d2 commit a93e6eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit a93e6eb

Please sign in to comment.