Skip to content

Commit 1987444

Browse files
author
Nick Frasser
authored
Add support for mentions containing dots (#185)
Fixes #175
1 parent e15b636 commit 1987444

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/linkify/plugins/mention.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default function mention(linkify) {
1313
const TT_SLASH = TT.SLASH;
1414
const TT_TLD = TT.TLD;
1515
const TT_UNDERSCORE = TT.UNDERSCORE;
16+
const TT_DOT = TT.DOT;
1617

1718
function MENTION(value) {
1819
this.v = value;
@@ -29,14 +30,16 @@ export default function mention(linkify) {
2930
const S_AT = S_START.jump(TT.AT); // @
3031
const S_AT_SYMS = new State();
3132
const S_MENTION = new State(MENTION);
32-
const S_MENTION_SLASH = new State();
33-
const S_MENTION_SLASH_SYMS = new State();
33+
const S_MENTION_DIVIDER = new State();
34+
const S_MENTION_DIVIDER_SYMS = new State();
3435

3536
// @_,
3637
S_AT.on(TT_UNDERSCORE, S_AT_SYMS);
3738

3839
// @_*
39-
S_AT_SYMS.on(TT_UNDERSCORE, S_AT_SYMS);
40+
S_AT_SYMS
41+
.on(TT_UNDERSCORE, S_AT_SYMS)
42+
.on(TT_DOT, S_AT_SYMS);
4043

4144
// Valid mention (not made up entirely of symbols)
4245
S_AT
@@ -59,23 +62,26 @@ export default function mention(linkify) {
5962
.on(TT_NUM, S_MENTION)
6063
.on(TT_UNDERSCORE, S_MENTION);
6164

62-
// Mention with a slash
63-
S_MENTION.on(TT_SLASH, S_MENTION_SLASH);
65+
// Mention with a divider
66+
S_MENTION
67+
.on(TT_SLASH, S_MENTION_DIVIDER)
68+
.on(TT_DOT, S_MENTION_DIVIDER);
6469

6570
// Mention _ trailing stash plus syms
66-
S_MENTION_SLASH.on(TT_UNDERSCORE, S_MENTION_SLASH_SYMS);
67-
S_MENTION_SLASH_SYMS.on(TT_UNDERSCORE, S_MENTION_SLASH_SYMS);
71+
S_MENTION_DIVIDER.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS);
72+
S_MENTION_DIVIDER_SYMS.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS);
6873

6974
// Once we get a word token, mentions can start up again
70-
S_MENTION_SLASH
75+
S_MENTION_DIVIDER
7176
.on(TT_DOMAIN, S_MENTION)
7277
.on(TT_LOCALHOST, S_MENTION)
7378
.on(TT_TLD, S_MENTION)
7479
.on(TT_NUM, S_MENTION);
7580

76-
S_MENTION_SLASH_SYMS
81+
S_MENTION_DIVIDER_SYMS
7782
.on(TT_DOMAIN, S_MENTION)
7883
.on(TT_LOCALHOST, S_MENTION)
7984
.on(TT_TLD, S_MENTION)
8085
.on(TT_NUM, S_MENTION);
86+
8187
}

test/spec/linkify/plugins/mention-test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('linkify/plugins/mention', () => {
5858
}]);
5959
});
6060

61-
it('parses mentions github team-style mentions with slashes', () => {
61+
it('parses github team-style mentions with slashes', () => {
6262
expect(linkify.find('Hey @500px/web please review this')).to.deep.equal([{
6363
type: 'mention',
6464
value: '@500px/web',
@@ -78,6 +78,26 @@ describe('linkify/plugins/mention', () => {
7878
}]);
7979
});
8080

81+
it('parses mentions with dots', () => {
82+
expect(linkify.find('Hey @john.doe please review this')).to.deep.equal([{
83+
type: 'mention',
84+
value: '@john.doe',
85+
href: '/john.doe'
86+
}]);
87+
});
88+
89+
it('ignores extra dots at the end of mentions', () => {
90+
expect(linkify.find('We should get ...@[email protected].... to be awesome')).to.deep.equal([{
91+
type: 'mention',
92+
value: '@soapbox._developers',
93+
href: '/soapbox._developers'
94+
}, {
95+
type: 'mention',
96+
value: '@soapbox.cs',
97+
href: '/soapbox.cs'
98+
}]);
99+
});
100+
81101
it('does not treat @/.* as a mention', () => {
82102
expect(linkify.find('What about @/ and @/nfrasser?')).to.deep.equal([]);
83103
});

0 commit comments

Comments
 (0)