mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-24 23:26:07 +09:00
[MFM] Fix hashtag detection
This commit is contained in:
parent
8d536af5ba
commit
d75a6faeba
@ -112,7 +112,7 @@ const mfm = P.createLanguage({
|
|||||||
const text = input.substr(i);
|
const text = input.substr(i);
|
||||||
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
||||||
if (!match) return P.makeFailure(i, 'not a hashtag');
|
if (!match) return P.makeFailure(i, 'not a hashtag');
|
||||||
if (match[1].match(/[0-9]+/)) return P.makeFailure(i, 'not a hashtag');
|
if (match[1].match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
|
||||||
if (input[i - 1] != '\n' && input[i - 1] != ' ' && input[i - 1] != null) return P.makeFailure(i, 'require space before "#"');
|
if (input[i - 1] != '\n' && input[i - 1] != ' ' && input[i - 1] != null) return P.makeFailure(i, 'require space before "#"');
|
||||||
return P.makeSuccess(i + match[0].length, makeNode('hashtag', { hashtag: match[1] }));
|
return P.makeSuccess(i + match[0].length, makeNode('hashtag', { hashtag: match[1] }));
|
||||||
}),
|
}),
|
||||||
|
@ -205,6 +205,13 @@ describe('Text', () => {
|
|||||||
], tokens);
|
], tokens);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allow including number', () => {
|
||||||
|
const tokens = analyze('#foo123');
|
||||||
|
assert.deepEqual([
|
||||||
|
node('hashtag', { hashtag: 'foo123' }),
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
it('disallow number only', () => {
|
it('disallow number only', () => {
|
||||||
const tokens = analyze('#123');
|
const tokens = analyze('#123');
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
|
Loading…
Reference in New Issue
Block a user