From 1ad3a348f660ee36b023c9a0525413aecb7476fd Mon Sep 17 00:00:00 2001 From: marihachi Date: Fri, 15 Aug 2025 18:32:12 +0900 Subject: [PATCH 1/3] update search syntax --- docs/syntax.md | 2 -- src/internal/parser.ts | 12 ++++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 29ae576..12b0586 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -58,8 +58,6 @@ ## 形式 ``` -MFM 書き方 Search -MFM 書き方 検索 MFM 書き方 [Search] MFM 書き方 [検索] ``` diff --git a/src/internal/parser.ts b/src/internal/parser.ts index 2eaf89c..db9838f 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -770,10 +770,14 @@ export const language = P.createLanguage({ }, search: () => { - const button = P.alt([ - P.regexp(/\[(検索|search)\]/i), - P.regexp(/(検索|search)/i), - ]); + const button = P.seq( + P.str('['), + P.alt([ + P.str('検索'), + P.str('search'), + ]), + P.str(']'), + ).text(); return P.seq( newLine.option(), P.lineBegin, From 5609279ea3e486e0fbd6c4d549afcfe739a41365 Mon Sep 17 00:00:00 2001 From: marihachi Date: Fri, 15 Aug 2025 18:37:15 +0900 Subject: [PATCH 2/3] update test --- test/parser.ts | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/test/parser.ts b/test/parser.ts index 0f7575a..35977d1 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -185,7 +185,7 @@ hoge`; describe('search', () => { describe('検索構文を使用できる', () => { test('Search', () => { - const input = 'MFM 書き方 123 Search'; + const input = 'MFM 書き方 123 [Search]'; const output = [ SEARCH('MFM 書き方 123', input) ]; @@ -198,13 +198,6 @@ hoge`; ]; assert.deepStrictEqual(mfm.parse(input), output); }); - test('search', () => { - const input = 'MFM 書き方 123 search'; - const output = [ - SEARCH('MFM 書き方 123', input) - ]; - assert.deepStrictEqual(mfm.parse(input), output); - }); test('[search]', () => { const input = 'MFM 書き方 123 [search]'; const output = [ @@ -212,13 +205,6 @@ hoge`; ]; assert.deepStrictEqual(mfm.parse(input), output); }); - test('検索', () => { - const input = 'MFM 書き方 123 検索'; - const output = [ - SEARCH('MFM 書き方 123', input) - ]; - assert.deepStrictEqual(mfm.parse(input), output); - }); test('[検索]', () => { const input = 'MFM 書き方 123 [検索]'; const output = [ @@ -228,10 +214,10 @@ hoge`; }); }); test('ブロックの前後にあるテキストが正しく解釈される', () => { - const input = 'abc\nhoge piyo bebeyo 検索\n123'; + const input = 'abc\nhoge piyo bebeyo [検索]\n123'; const output = [ TEXT('abc'), - SEARCH('hoge piyo bebeyo', 'hoge piyo bebeyo 検索'), + SEARCH('hoge piyo bebeyo', 'hoge piyo bebeyo [検索]'), TEXT('123') ]; assert.deepStrictEqual(mfm.parse(input), output); From 4226fa5d2df1a23a95946c35c900103225d4124e Mon Sep 17 00:00:00 2001 From: marihachi Date: Fri, 15 Aug 2025 18:37:31 +0900 Subject: [PATCH 3/3] fix parser --- src/internal/parser.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/internal/parser.ts b/src/internal/parser.ts index db9838f..452ea85 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -770,14 +770,7 @@ export const language = P.createLanguage({ }, search: () => { - const button = P.seq( - P.str('['), - P.alt([ - P.str('検索'), - P.str('search'), - ]), - P.str(']'), - ).text(); + const button = P.regexp(/\[(search|検索)\]/i); return P.seq( newLine.option(), P.lineBegin,