From 31929dad61cb72b367d1ffe1de9b1fd05a52d80a Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 6 Feb 2019 00:05:26 +0900 Subject: [PATCH] [MFM] Better hashtag parsing: Ignore slash --- src/mfm/language.ts | 2 +- test/mfm.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mfm/language.ts b/src/mfm/language.ts index 8f35d443dc..bfb0f249c2 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -142,7 +142,7 @@ export const mfmLanguage = P.createLanguage({ }, hashtag: () => P((input, 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'); let hashtag = match[1]; hashtag = removeOrphanedBrackets(hashtag); diff --git a/test/mfm.ts b/test/mfm.ts index 8d5496a5f8..7db94b45e1 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -611,6 +611,14 @@ describe('MFM', () => { text('(#123)'), ]); }); + + it('ignore slash', () => { + const tokens = parse('#foo/bar'); + assert.deepStrictEqual(tokens, [ + leaf('hashtag', { hashtag: 'foo' }), + text('/bar'), + ]); + }); }); describe('quote', () => {