Skip to content

Commit

Permalink
feat(message-parser): Add Matrix Protocol username pattern to User Me…
Browse files Browse the repository at this point in the history
…ntion (#847)
  • Loading branch information
hugocostadev authored Sep 15, 2022
1 parent 24ea801 commit 702c1ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/message-parser/src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,15 @@ SectionText

utf8_names_validation = $[0-9a-zA-Z-_.]+

matrix_server_validation = ":" utf8_names_validation

UserMention
= t:Text "@"+ user:utf8_names_validation {
return reducePlainTexts([t, plain('@' + user)])[0];
}
/ "@"+ user:$(utf8_names_validation matrix_server_validation) {
return mentionUser(user);
}
/ "@"+ user:utf8_names_validation { return mentionUser(user); }

ChannelMention
Expand Down
5 changes: 5 additions & 0 deletions packages/message-parser/tests/mention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ test.each([
[paragraph([mentionUser('guilherme.gazzo.'), plain(' ')])],
],
['#GENERAL', [paragraph([mentionChannel('GENERAL')])]],
['@user:server.com', [paragraph([mentionUser('user:server.com')])]],
[
'@marcos.defendi:matrix.org',
[paragraph([mentionUser('marcos.defendi:matrix.org')])],
],
])('parses %p', (input, output) => {
expect(parse(input)).toMatchObject(output);
});

0 comments on commit 702c1ee

Please sign in to comment.