[MFM] Improve hashtag parsing

This commit is contained in:
syuilo 2019-03-05 22:18:29 +09:00
parent f7890b696d
commit 1536232f8b
2 changed files with 9 additions and 1 deletions

View File

@ -142,7 +142,7 @@ export const mfmLanguage = P.createLanguage({
}, },
hashtag: () => P((input, i) => { hashtag: () => P((input, i) => {
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');
let hashtag = match[1]; let hashtag = match[1];
hashtag = removeOrphanedBrackets(hashtag); hashtag = removeOrphanedBrackets(hashtag);

View File

@ -550,6 +550,14 @@ describe('MFM', () => {
]); ]);
}); });
it('ignore square brackets', () => {
const tokens = parse('#foo]');
assert.deepStrictEqual(tokens, [
leaf('hashtag', { hashtag: 'foo' }),
text(']'),
]);
});
it('allow including number', () => { it('allow including number', () => {
const tokens = parse('#foo123'); const tokens = parse('#foo123');
assert.deepStrictEqual(tokens, [ assert.deepStrictEqual(tokens, [