allow "math block" inline

previously, a math block would only be recognised when on its own
line
This commit is contained in:
dakkar 2024-01-02 16:14:14 +00:00
parent 3eb78bc54f
commit 5f50e38f31
2 changed files with 7 additions and 7 deletions

View file

@ -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);
});
},

View file

@ -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);
});