From 5f50e38f31266b76e51e4c9b129d95cace6e6032 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 2 Jan 2024 16:14:14 +0000 Subject: [PATCH] allow "math block" inline previously, a math block would only be recognised when on its own line --- src/internal/parser.ts | 4 +--- test/parser.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/internal/parser.ts b/src/internal/parser.ts index f50978d..b2bf6b5 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -247,16 +247,14 @@ export const language = P.createLanguage({ const close = P.str('\\]'); return P.seq([ newLine.option(), - P.lineBegin, open, newLine.option(), P.seq([P.notMatch(P.seq([newLine.option(), close])), P.char], 1).many(1), newLine.option(), close, - P.lineEnd, newLine.option(), ]).map(result => { - const formula = (result[4] as string[]).join(''); + const formula = (result[3] as string[]).join(''); return M.MATH_BLOCK(formula); }); }, diff --git a/test/parser.ts b/test/parser.ts index e4c1552..d3000df 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -291,17 +291,19 @@ hoge`; ]; assert.deepStrictEqual(mfm.parse(input), output); }); - test('行末以外に閉じタグがある場合はマッチしない', () => { + test('行末以外に閉じタグがある場合はマッチする', () => { const input = '\\[aaa\\]after'; const output = [ - TEXT('\\[aaa\\]after') + MATH_BLOCK('aaa'), + TEXT('after'), ]; assert.deepStrictEqual(mfm.parse(input), output); }); - test('行頭以外に開始タグがある場合はマッチしない', () => { + test('行頭以外に開始タグがある場合はマッチする', () => { const input = 'before\\[aaa\\]'; const output = [ - TEXT('before\\[aaa\\]') + TEXT('before'), + MATH_BLOCK('aaa'), ]; assert.deepStrictEqual(mfm.parse(input), output); });