Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/internal/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Args = Record<string, string | true>;
const space = P.regexp(/[\u0020\u3000\t]/);
const alphaAndNum = P.regexp(/[a-z0-9]/i);
const newLine = P.alt([P.crlf, P.cr, P.lf]);
const asciiPunctuation = P.regexp(/[!#$%&'()*+,-./:;<=>?@\[\\\]^_`{|}~]/);

function seqOrText<Parsers extends P.Parser<unknown>[]>(...parsers: Parsers): P.Parser<SeqParseResult<Parsers> | string> {
return new P.Parser<SeqParseResult<Parsers> | string>((input, index, state) => {
Expand Down Expand Up @@ -794,5 +795,10 @@ export const language = P.createLanguage<TypeTable>({
});
},

text: () => P.char,
text: () => {
return P.alt([
P.seq(P.str('\\'), asciiPunctuation).select(1),
P.char,
]);
},
});
26 changes: 24 additions & 2 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ hoge`;
test('行末以外に閉じタグがある場合はマッチしない', () => {
const input = '\\[aaa\\]after';
const output = [
TEXT('\\[aaa\\]after')
TEXT('[aaa]after')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
test('行頭以外に開始タグがある場合はマッチしない', () => {
const input = 'before\\[aaa\\]';
const output = [
TEXT('before\\[aaa\\]')
TEXT('before[aaa]')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
Expand Down Expand Up @@ -1086,6 +1086,28 @@ hoge`;
assert.deepStrictEqual(mfm.parse(input), output);
});

test('with escaped text', () => {
const input = 'Ai said: ["Misskey.io \\[is\\] the official instance"](https://xn--931a.moe/).';
const output = [
TEXT('Ai said: '),
LINK(false, 'https://xn--931a.moe/', [
TEXT('"Misskey.io [is] the official instance"')
]),
TEXT('.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});

test('with double escaped text', () => {
const input = 'Ai said: ["Misskey.io \\\\[is\\\\] the official instance"](https://xn--931a.moe/).';
const output = [
TEXT('Ai said: '),
LINK(false, 'https://xn--931a.moe/', [
TEXT('"Misskey.io \\[is\\] the official instance"')
]),
];
});

test('with angle brackets url', () => {
const input = '[official instance](<https://misskey.io/@ai>).';
const output = [
Expand Down