From c58027e5217c72a6c936aa27b4b02f0ff7f5bbda Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Sun, 2 Dec 2018 06:53:57 +0900
Subject: [PATCH] [MFM] Better hashtag detection

---
 src/mfm/parser.ts | 2 +-
 test/mfm.ts       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts
index 467097d4f1..3e77d56435 100644
--- a/src/mfm/parser.ts
+++ b/src/mfm/parser.ts
@@ -162,7 +162,7 @@ const mfm = P.createLanguage({
 			let hashtag = match[1];
 			hashtag = hashtag.substr(0, getTrailingPosition(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 (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a hashtag');
 			return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
 		}),
 	//#endregion
diff --git a/test/mfm.ts b/test/mfm.ts
index bfbf595f1c..eeb92aa2af 100644
--- a/test/mfm.ts
+++ b/test/mfm.ts
@@ -187,9 +187,9 @@ describe('Text', () => {
 			});
 
 			it('with text (zenkaku)', () => {
-				const tokens = analyze('こんにちは #世界');
+				const tokens = analyze('こんにちは#世界');
 				assert.deepEqual([
-					text('こんにちは '),
+					text('こんにちは'),
 					node('hashtag', { hashtag: '世界' })
 				], tokens);
 			});