Skip to content

Commit e4b161a

Browse files
authored
Fix hashtag plugin: add support for full width middle dot (#492)
1 parent cc5c5fa commit e4b161a

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

packages/linkify-plugin-hashtag/src/hashtag.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const HashtagToken = createTokenClass('hashtag', { isLink: true });
66
/**
77
* @type {import('linkifyjs').Plugin}
88
*/
9-
export default function hashtag({ scanner, parser }) {
9+
export default function hashtag({ scanner, parser }) {
1010
// Various tokens that may compose a hashtag
11-
const { POUND, UNDERSCORE } = scanner.tokens;
11+
const { POUND, UNDERSCORE, FULLWIDTHMIDDLEDOT } = scanner.tokens;
1212
const { alpha, numeric, alphanumeric, emoji } = scanner.tokens.groups;
1313

1414
// Take or create a transition from start to the '#' sign (non-accepting)
@@ -21,11 +21,14 @@ const HashtagToken = createTokenClass('hashtag', { isLink: true });
2121
Hash.ta(numeric, HashPrefix);
2222
Hash.ta(alpha, Hashtag);
2323
Hash.ta(emoji, Hashtag);
24+
Hash.ta(FULLWIDTHMIDDLEDOT, Hashtag);
2425
HashPrefix.ta(alpha, Hashtag);
2526
HashPrefix.ta(emoji, Hashtag);
27+
HashPrefix.ta(FULLWIDTHMIDDLEDOT, Hashtag);
2628
HashPrefix.ta(numeric, HashPrefix);
2729
HashPrefix.tt(UNDERSCORE, HashPrefix);
2830
Hashtag.ta(alphanumeric, Hashtag);
2931
Hashtag.ta(emoji, Hashtag);
32+
Hashtag.tt(FULLWIDTHMIDDLEDOT, Hashtag);
3033
Hashtag.tt(UNDERSCORE, Hashtag); // Trailing underscore is okay
3134
}

packages/linkifyjs/src/scanner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function init(customSchemes = []) {
9494
tt(Start, '~', tk.TILDE);
9595
tt(Start, '_', tk.UNDERSCORE);
9696
tt(Start, '\\', tk.BACKSLASH);
97+
tt(Start, '・', tk.FULLWIDTHMIDDLEDOT);
9798

9899
const Num = tr(Start, re.DIGIT, tk.NUM, { [fsm.numeric]: true });
99100
tr(Num, re.DIGIT, Num);

packages/linkifyjs/src/text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const PLUS = 'PLUS'; // +
7676
export const POUND = 'POUND'; // #
7777
export const QUERY = 'QUERY'; // ?
7878
export const QUOTE = 'QUOTE'; // "
79+
export const FULLWIDTHMIDDLEDOT = 'FULLWIDTHMIDDLEDOT'; // ・
7980

8081
export const SEMI = 'SEMI'; // ;
8182
export const SLASH = 'SLASH'; // /

test/spec/linkify-plugin-hashtag.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ describe('linkify-plugin-hashtag', () => {
8080
expect(linkify.test('#سلام', 'hashtag')).to.be.ok;
8181
});
8282

83+
it('Works with Japanese characters', () => {
84+
expect(linkify.test('#おはよう', 'hashtag')).to.be.ok;
85+
});
86+
87+
it('Works with Japanese characters and full width middle dot', () => {
88+
expect(linkify.test('#おは・よう', 'hashtag')).to.be.ok;
89+
});
90+
8391
it('Works with emojis', () => {
8492
expect(linkify.test('#🍭', 'hashtag')).to.be.ok;
8593
});

test/spec/linkifyjs/scanner.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const tests = [
2727
['$', [t.DOLLAR], ['$']],
2828
['=', [t.EQUALS], ['=']],
2929
['-', [t.HYPHEN], ['-']],
30+
['・', [t.FULLWIDTHMIDDLEDOT], ['・']],
3031
['&?<>(', [t.AMPERSAND, t.QUERY, t.OPENANGLEBRACKET, t.CLOSEANGLEBRACKET, t.OPENPAREN], ['&', '?', '<', '>', '(']],
3132
['([{}])', [t.OPENPAREN, t.OPENBRACKET, t.OPENBRACE, t.CLOSEBRACE, t.CLOSEBRACKET, t.CLOSEPAREN], ['(', '[', '{', '}', ']', ')']],
3233
['!,;\'', [t.EXCLAMATION, t.COMMA, t.SEMI, t.APOSTROPHE], ['!', ',', ';', '\'']],
@@ -83,6 +84,11 @@ const tests = [
8384
[t.POUND, t.UWORD, t.UNDERSCORE, t.UWORD, t.WS, t.POUND, t.UWORD, t.WS, t.POUND, t.UWORD],
8485
['#', 'АБВ', '_', 'бв', ' ', '#', '한글', ' ', '#', 'سلام']
8586
],
87+
[
88+
'#おは・よう',
89+
[t.POUND, t.UWORD, t.FULLWIDTHMIDDLEDOT, t.UWORD],
90+
['#', 'おは', '・', 'よう']
91+
],
8692
[
8793
'テストexample.comテスト',
8894
[t.UWORD, t.WORD, t.DOT, t.TLD, t.UWORD],

0 commit comments

Comments
 (0)