Skip to content

Commit 702c1ee

Browse files
authored
feat(message-parser): Add Matrix Protocol username pattern to User Mention (#847)
1 parent 24ea801 commit 702c1ee

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/message-parser/src/grammar.pegjs

+5
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,15 @@ SectionText
186186

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

189+
matrix_server_validation = ":" utf8_names_validation
190+
189191
UserMention
190192
= t:Text "@"+ user:utf8_names_validation {
191193
return reducePlainTexts([t, plain('@' + user)])[0];
192194
}
195+
/ "@"+ user:$(utf8_names_validation matrix_server_validation) {
196+
return mentionUser(user);
197+
}
193198
/ "@"+ user:utf8_names_validation { return mentionUser(user); }
194199

195200
ChannelMention

packages/message-parser/tests/mention.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ test.each([
88
[paragraph([mentionUser('guilherme.gazzo.'), plain(' ')])],
99
],
1010
['#GENERAL', [paragraph([mentionChannel('GENERAL')])]],
11+
['@user:server.com', [paragraph([mentionUser('user:server.com')])]],
12+
[
13+
'@marcos.defendi:matrix.org',
14+
[paragraph([mentionUser('marcos.defendi:matrix.org')])],
15+
],
1116
])('parses %p', (input, output) => {
1217
expect(parse(input)).toMatchObject(output);
1318
});

0 commit comments

Comments
 (0)