mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-24 23:26:44 -06:00
[MFM] Improve hashtag detection
This commit is contained in:
parent
0489291815
commit
48d0e2fa5f
2 changed files with 9 additions and 1 deletions
|
@ -162,7 +162,7 @@ const mfm = P.createLanguage({
|
||||||
let hashtag = match[1];
|
let hashtag = match[1];
|
||||||
hashtag = hashtag.substr(0, getTrailingPosition(hashtag));
|
hashtag = hashtag.substr(0, getTrailingPosition(hashtag));
|
||||||
if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
|
if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
|
||||||
if (!['\n', ' ', '(', '「', null, undefined].includes(input[i - 1])) return P.makeFailure(i, 'require space before "#"');
|
if (!['\n', ' ', ' ', '(', '「', null, undefined].includes(input[i - 1])) return P.makeFailure(i, 'require space before "#"');
|
||||||
return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
|
return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
|
||||||
}),
|
}),
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
|
@ -186,6 +186,14 @@ describe('Text', () => {
|
||||||
], tokens);
|
], tokens);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('with text (zenkaku)', () => {
|
||||||
|
const tokens = analyze('こんにちは #世界');
|
||||||
|
assert.deepEqual([
|
||||||
|
text('こんにちは '),
|
||||||
|
node('hashtag', { hashtag: '世界' })
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
it('ignore comma and period', () => {
|
it('ignore comma and period', () => {
|
||||||
const tokens = analyze('Foo #bar, baz #piyo.');
|
const tokens = analyze('Foo #bar, baz #piyo.');
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
|
|
Loading…
Reference in a new issue