From 8134df00a6b0cd67a55d6e6f25330e58a5f34750 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 23 Jun 2018 19:31:28 +0900 Subject: [PATCH] MFM: Improve search syntax --- src/mfm/parse/elements/search.ts | 2 +- test/mfm.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/mfm/parse/elements/search.ts b/src/mfm/parse/elements/search.ts index e5d9b9f0c..9c4b7ffbe 100644 --- a/src/mfm/parse/elements/search.ts +++ b/src/mfm/parse/elements/search.ts @@ -9,7 +9,7 @@ export type TextElementSearch = { }; export default function(text: string) { - const match = text.match(/^(.+?) 検索(\n|$)/); + const match = text.match(/^(.+?) (検索|Search)(\n|$)/i); if (!match) return null; return { type: 'search', diff --git a/test/mfm.ts b/test/mfm.ts index de722bffb..f7fa1c0f5 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -93,6 +93,28 @@ describe('Text', () => { assert.equal(tokens[0].type, 'inline-code'); assert.equal(tokens[0].content, '`var x = "Strawberry Pasta";`'); }); + + it('search', () => { + const tokens1 = analyze('a b c 検索'); + assert.deepEqual([ + { type: 'search', content: 'a b c 検索', query: 'a b c'} + ], tokens1); + + const tokens2 = analyze('a b c Search'); + assert.deepEqual([ + { type: 'search', content: 'a b c Search', query: 'a b c'} + ], tokens2); + + const tokens3 = analyze('a b c search'); + assert.deepEqual([ + { type: 'search', content: 'a b c search', query: 'a b c'} + ], tokens3); + + const tokens4 = analyze('a b c SEARCH'); + assert.deepEqual([ + { type: 'search', content: 'a b c SEARCH', query: 'a b c'} + ], tokens4); + }); }); describe('syntax highlighting', () => {