sfm-js/test/parser.ts

1553 lines
38 KiB
TypeScript
Raw Normal View History

2021-04-03 12:04:53 +00:00
import assert from 'assert';
2021-06-26 14:48:46 +00:00
import * as mfm from '../src/index';
2021-04-03 12:04:53 +00:00
import {
TEXT, CENTER, FN, UNI_EMOJI, MENTION, EMOJI_CODE, HASHTAG, N_URL, BOLD, SMALL, ITALIC, STRIKE, QUOTE, MATH_BLOCK, SEARCH, CODE_BLOCK, LINK, INLINE_CODE, MATH_INLINE, PLAIN
2021-06-26 14:48:46 +00:00
} from '../src/index';
2021-04-03 12:04:53 +00:00
describe('SimpleParser', () => {
2021-04-15 04:51:23 +00:00
describe('text', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-15 04:51:23 +00:00
const input = 'abc';
const output = [TEXT('abc')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-04-15 04:51:23 +00:00
});
2023-02-04 00:30:39 +00:00
test('ignore hashtag', () => {
2021-04-15 04:51:23 +00:00
const input = 'abc#abc';
const output = [TEXT('abc#abc')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-04-15 04:51:23 +00:00
});
2023-02-04 00:30:39 +00:00
test('keycap number sign', () => {
2021-04-15 04:51:23 +00:00
const input = 'abc#⃣abc';
const output = [TEXT('abc'), UNI_EMOJI('#️⃣'), TEXT('abc')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-04-15 04:51:23 +00:00
});
});
2021-06-05 07:46:54 +00:00
describe('emoji', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-06-05 07:46:54 +00:00
const input = ':foo:';
const output = [EMOJI_CODE('foo')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-06-05 07:46:54 +00:00
});
2023-02-04 00:30:39 +00:00
test('between texts', () => {
2021-06-05 07:46:54 +00:00
const input = 'foo:bar:baz';
2023-01-09 07:05:16 +00:00
const output = [TEXT('foo:bar:baz')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
});
2023-02-04 00:30:39 +00:00
test('between texts 2', () => {
2023-01-09 07:05:16 +00:00
const input = '12:34:56';
const output = [TEXT('12:34:56')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
});
2023-02-04 00:30:39 +00:00
test('between texts 3', () => {
2023-01-09 07:05:16 +00:00
const input = 'あ:bar:い';
const output = [TEXT('あ'), EMOJI_CODE('bar'), TEXT('い')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-06-05 07:46:54 +00:00
});
});
2023-02-04 00:30:39 +00:00
test('disallow other syntaxes', () => {
2021-06-05 07:46:54 +00:00
const input = 'foo **bar** baz';
const output = [TEXT('foo **bar** baz')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
2021-06-05 07:46:54 +00:00
});
2021-04-15 04:51:23 +00:00
});
describe('FullParser', () => {
2021-04-03 12:04:53 +00:00
describe('text', () => {
2023-02-04 00:30:39 +00:00
test('普通のテキストを入力すると1つのテキストードが返される', () => {
2021-04-03 12:04:53 +00:00
const input = 'abc';
const output = [TEXT('abc')];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('quote', () => {
2023-02-04 00:30:39 +00:00
test('1行の引用ブロックを使用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '> abc';
const output = [
QUOTE([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('複数行の引用ブロックを使用できる', () => {
2021-04-03 12:04:53 +00:00
const input = `
> abc
> 123
`;
const output = [
QUOTE([
TEXT('abc\n123')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('引用ブロックはブロックをネストできる', () => {
2021-04-03 12:04:53 +00:00
const input = `
> <center>
> a
> </center>
`;
const output = [
QUOTE([
CENTER([
TEXT('a')
])
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('引用ブロックはインライン構文を含んだブロックをネストできる', () => {
2021-04-03 12:04:53 +00:00
const input = `
> <center>
> I'm @ai, An bot of misskey!
> </center>
`;
const output = [
QUOTE([
CENTER([
TEXT('I\'m '),
MENTION('ai', null, '@ai'),
TEXT(', An bot of misskey!'),
])
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('複数行の引用ブロックでは空行を含めることができる', () => {
2021-04-17 06:35:07 +00:00
const input = `
> abc
>
> 123
`;
const output = [
QUOTE([
TEXT('abc\n\n123')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('1行の引用ブロックを空行にはできない', () => {
2021-07-31 06:12:43 +00:00
const input = '> ';
2021-04-17 06:35:07 +00:00
const output = [
TEXT('> ')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('引用ブロックの後ろの空行は無視される', () => {
2021-06-12 03:53:11 +00:00
const input = `
> foo
> bar
hoge`;
const output = [
QUOTE([
TEXT('foo\nbar')
]),
TEXT('hoge')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('2つの引用行の間に空行がある場合は2つの引用ブロックが生成される', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = `
> foo
> bar
hoge`;
const output = [
QUOTE([
TEXT('foo')
]),
QUOTE([
TEXT('bar')
]),
TEXT('hoge'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('search', () => {
2021-04-03 12:34:08 +00:00
describe('検索構文を使用できる', () => {
2023-02-04 00:30:39 +00:00
test('Search', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 Search';
const output = [
2023-12-26 17:15:52 +00:00
TEXT('MFM 書き方 123 Search')
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('[Search]', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 [Search]';
const output = [
2021-04-10 09:09:44 +00:00
SEARCH('MFM 書き方 123', input)
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('search', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 search';
const output = [
2023-12-26 17:15:52 +00:00
TEXT('MFM 書き方 123 search')
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('[search]', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 [search]';
const output = [
2021-04-10 09:09:44 +00:00
SEARCH('MFM 書き方 123', input)
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('検索', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 検索';
const output = [
2023-12-26 17:15:52 +00:00
TEXT('MFM 書き方 123 検索')
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('[検索]', () => {
2021-04-03 12:04:53 +00:00
const input = 'MFM 書き方 123 [検索]';
const output = [
2021-04-10 09:09:44 +00:00
SEARCH('MFM 書き方 123', input)
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
2023-02-04 00:30:39 +00:00
test('ブロックの前後にあるテキストが正しく解釈される', () => {
2021-04-03 12:04:53 +00:00
const input = 'abc\nhoge piyo bebeyo 検索\n123';
const output = [
2023-12-26 17:15:52 +00:00
TEXT('abc\nhoge piyo bebeyo 検索\n123')
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('code block', () => {
2023-02-04 00:30:39 +00:00
test('コードブロックを使用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '```\nabc\n```';
const output = [CODE_BLOCK('abc', null)];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 07:23:49 +00:00
2023-02-04 00:30:39 +00:00
test('コードブロックには複数行のコードを入力できる', () => {
2021-04-03 12:04:53 +00:00
const input = '```\na\nb\nc\n```';
const output = [CODE_BLOCK('a\nb\nc', null)];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 07:23:49 +00:00
2023-02-04 00:30:39 +00:00
test('コードブロックは言語を指定できる', () => {
2021-04-03 12:04:53 +00:00
const input = '```js\nconst a = 1;\n```';
const output = [CODE_BLOCK('const a = 1;', 'js')];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 07:23:49 +00:00
2023-02-04 00:30:39 +00:00
test('ブロックの前後にあるテキストが正しく解釈される', () => {
2021-04-03 12:04:53 +00:00
const input = 'abc\n```\nconst abc = 1;\n```\n123';
const output = [
TEXT('abc'),
CODE_BLOCK('const abc = 1;', null),
TEXT('123')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 07:23:49 +00:00
2023-02-04 00:30:39 +00:00
test('ignore internal marker', () => {
2021-06-05 07:23:49 +00:00
const input = '```\naaa```bbb\n```';
const output = [CODE_BLOCK('aaa```bbb', null)];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('trim after line break', () => {
2021-06-05 07:23:49 +00:00
const input = '```\nfoo\n```\nbar';
const output = [
CODE_BLOCK('foo', null),
TEXT('bar'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('mathBlock', () => {
2023-02-04 00:30:39 +00:00
test('1行の数式ブロックを使用できる', () => {
2021-04-03 12:34:08 +00:00
const input = '\\[math1\\]';
const output = [
MATH_BLOCK('math1')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:34:08 +00:00
});
2023-02-04 00:30:39 +00:00
test('ブロックの前後にあるテキストが正しく解釈される', () => {
2021-04-03 12:34:08 +00:00
const input = 'abc\n\\[math1\\]\n123';
2021-04-03 12:04:53 +00:00
const output = [
TEXT('abc'),
2021-04-03 12:34:08 +00:00
MATH_BLOCK('math1'),
TEXT('123')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:34:08 +00:00
});
test('行末以外に閉じタグがある場合はマッチする', () => {
2021-04-03 12:34:08 +00:00
const input = '\\[aaa\\]after';
const output = [
MATH_BLOCK('aaa'),
TEXT('after'),
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
test('行頭以外に開始タグがある場合はマッチする', () => {
2021-04-03 12:34:08 +00:00
const input = 'before\\[aaa\\]';
2021-04-03 12:04:53 +00:00
const output = [
TEXT('before'),
MATH_BLOCK('aaa'),
2021-04-03 12:04:53 +00:00
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('center', () => {
2023-02-04 00:30:39 +00:00
test('single text', () => {
2021-04-03 12:04:53 +00:00
const input = '<center>abc</center>';
const output = [
CENTER([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('multiple text', () => {
2021-04-03 12:04:53 +00:00
const input = 'before\n<center>\nabc\n123\n\npiyo\n</center>\nafter';
const output = [
TEXT('before'),
CENTER([
TEXT('abc\n123\n\npiyo')
]),
TEXT('after')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('emoji code', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = ':abc:';
const output = [EMOJI_CODE('abc')];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('unicode emoji', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '今起きた😇';
const output = [TEXT('今起きた'), UNI_EMOJI('😇')];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-04-15 04:51:23 +00:00
2023-02-04 00:30:39 +00:00
test('keycap number sign', () => {
2021-04-15 04:51:23 +00:00
const input = 'abc#⃣123';
const output = [TEXT('abc'), UNI_EMOJI('#️⃣'), TEXT('123')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('big', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '***abc***';
const output = [
FN('tada', { }, [
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容にはインライン構文を利用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '***123**abc**123***';
const output = [
FN('tada', { }, [
TEXT('123'),
BOLD([
TEXT('abc')
]),
TEXT('123')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容は改行できる', () => {
2021-04-03 12:04:53 +00:00
const input = '***123\n**abc**\n123***';
const output = [
FN('tada', { }, [
TEXT('123\n'),
BOLD([
TEXT('abc')
]),
TEXT('\n123')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
2021-09-29 15:39:14 +00:00
describe('bold tag', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-09-29 15:39:14 +00:00
const input = '<b>abc</b>';
const output = [
BOLD([
TEXT('abc')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('inline syntax allowed inside', () => {
2021-09-29 15:39:14 +00:00
const input = '<b>123~~abc~~123</b>';
const output = [
BOLD([
TEXT('123'),
STRIKE([
TEXT('abc')
]),
TEXT('123')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('line breaks', () => {
2021-09-29 15:39:14 +00:00
const input = '<b>123\n~~abc~~\n123</b>';
const output = [
BOLD([
TEXT('123\n'),
STRIKE([
TEXT('abc')
]),
TEXT('\n123')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
2021-04-03 12:04:53 +00:00
describe('bold', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '**abc**';
const output = [
BOLD([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容にはインライン構文を利用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '**123~~abc~~123**';
const output = [
BOLD([
TEXT('123'),
STRIKE([
TEXT('abc')
]),
TEXT('123')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容は改行できる', () => {
2021-04-03 12:04:53 +00:00
const input = '**123\n~~abc~~\n123**';
const output = [
BOLD([
TEXT('123\n'),
STRIKE([
TEXT('abc')
]),
TEXT('\n123')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
describe('small', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '<small>abc</small>';
const output = [
SMALL([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容にはインライン構文を利用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '<small>abc**123**abc</small>';
const output = [
SMALL([
TEXT('abc'),
BOLD([
TEXT('123')
]),
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容は改行できる', () => {
2021-04-03 12:04:53 +00:00
const input = '<small>abc\n**123**\nabc</small>';
const output = [
SMALL([
TEXT('abc\n'),
BOLD([
TEXT('123')
]),
TEXT('\nabc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
2021-04-15 07:53:55 +00:00
describe('italic tag', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '<i>abc</i>';
const output = [
ITALIC([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容にはインライン構文を利用できる', () => {
2021-04-03 12:04:53 +00:00
const input = '<i>abc**123**abc</i>';
const output = [
ITALIC([
TEXT('abc'),
BOLD([
TEXT('123')
]),
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('内容は改行できる', () => {
2021-04-03 12:04:53 +00:00
const input = '<i>abc\n**123**\nabc</i>';
const output = [
ITALIC([
TEXT('abc\n'),
BOLD([
TEXT('123')
]),
TEXT('\nabc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});
2021-04-15 07:53:55 +00:00
describe('italic alt 1', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '*abc*';
const output = [
ITALIC([
TEXT('abc')
])
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-04-15 07:53:55 +00:00
2023-02-04 00:30:39 +00:00
test('basic 2', () => {
2021-04-15 07:53:55 +00:00
const input = 'before *abc* after';
const output = [
TEXT('before '),
ITALIC([
TEXT('abc')
]),
TEXT(' after')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-12-26 18:16:15 +00:00
test('basic non-ascii', () => {
const input = '*aßc*';
const output = [
ITALIC([
TEXT('aßc')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore a italic syntax if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
2021-05-06 15:28:24 +00:00
let input = 'before*abc*after';
let output: mfm.MfmNode[] = [TEXT('before*abc*after')];
assert.deepStrictEqual(mfm.parse(input), output);
input = 'あいう*abc*えお';
output = [
TEXT('あいう'),
ITALIC([
TEXT('abc')
]),
TEXT('えお')
];
2021-04-15 07:53:55 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
});
});
describe('italic alt 2', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-15 07:53:55 +00:00
const input = '_abc_';
const output = [
ITALIC([
TEXT('abc')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic 2', () => {
2021-04-15 07:53:55 +00:00
const input = 'before _abc_ after';
const output = [
TEXT('before '),
ITALIC([
TEXT('abc')
]),
TEXT(' after')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-12-26 18:16:15 +00:00
test('basic non-ascii', () => {
const input = '_abç_';
const output = [
ITALIC([
TEXT('abç')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore a italic syntax if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
2021-05-06 15:28:24 +00:00
let input = 'before_abc_after';
let output: mfm.MfmNode[] = [TEXT('before_abc_after')];
assert.deepStrictEqual(mfm.parse(input), output);
input = 'あいう_abc_えお';
output = [
TEXT('あいう'),
ITALIC([
TEXT('abc')
]),
TEXT('えお')
];
2021-04-15 07:53:55 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
2021-09-29 15:39:14 +00:00
describe('strike tag', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-09-29 15:39:14 +00:00
const input = '<s>foo</s>';
const output = [STRIKE([
TEXT('foo')
])];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
2021-06-06 14:54:51 +00:00
describe('strike', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-06-06 14:54:51 +00:00
const input = '~~foo~~';
const output = [STRIKE([
TEXT('foo')
])];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-12-26 18:16:15 +00:00
test('basic non-ascii', () => {
const input = '~~föo~~';
const output = [STRIKE([
TEXT('föo')
])];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-06-06 14:54:51 +00:00
});
2021-04-03 12:04:53 +00:00
2021-06-05 07:21:22 +00:00
describe('inlineCode', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-06-05 07:21:22 +00:00
const input = '`var x = "Strawberry Pasta";`';
const output = [INLINE_CODE('var x = "Strawberry Pasta";')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow line break', () => {
2021-06-05 07:21:22 +00:00
const input = '`foo\nbar`';
const output = [TEXT('`foo\nbar`')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow ´', () => {
2021-06-05 07:21:22 +00:00
const input = '`foo´bar`';
const output = [TEXT('`foo´bar`')];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
2021-04-03 12:04:53 +00:00
2021-06-07 14:27:45 +00:00
describe('mathInline', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-06-07 14:27:45 +00:00
const input = '\\(x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}\\)';
const output = [MATH_INLINE('x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}')];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
2021-04-03 12:04:53 +00:00
2021-04-15 06:51:08 +00:00
describe('mention', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-15 06:51:08 +00:00
const input = '@abc';
const output = [MENTION('abc', null, '@abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic 2', () => {
2021-04-15 06:51:08 +00:00
const input = 'before @abc after';
const output = [TEXT('before '), MENTION('abc', null, '@abc'), TEXT(' after')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic remote', () => {
2021-04-15 06:51:08 +00:00
const input = '@abc@misskey.io';
const output = [MENTION('abc', 'misskey.io', '@abc@misskey.io')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic remote 2', () => {
2021-04-15 06:51:08 +00:00
const input = 'before @abc@misskey.io after';
const output = [TEXT('before '), MENTION('abc', 'misskey.io', '@abc@misskey.io'), TEXT(' after')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic remote 3', () => {
2021-04-15 06:51:08 +00:00
const input = 'before\n@abc@misskey.io\nafter';
const output = [TEXT('before\n'), MENTION('abc', 'misskey.io', '@abc@misskey.io'), TEXT('\nafter')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore format of mail address', () => {
2021-04-15 06:51:08 +00:00
const input = 'abc@example.com';
const output = [TEXT('abc@example.com')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-05-06 15:28:24 +00:00
2023-02-04 00:30:39 +00:00
test('detect as a mention if the before char is [^a-z0-9]i', () => {
2021-05-06 15:28:24 +00:00
const input = 'あいう@abc';
const output = [TEXT('あいう'), MENTION('abc', null, '@abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
2023-02-04 00:30:39 +00:00
test('invalid char only username', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@-';
const output = [TEXT('@-')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('invalid char only hostname', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc@.';
const output = [TEXT('@abc@.')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('allow "-" in username', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc-d';
const output = [MENTION('abc-d', null, '@abc-d')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "-" in head of username', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@-abc';
const output = [TEXT('@-abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "-" in tail of username', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc-';
const output = [MENTION('abc', null, '@abc'), TEXT('-')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "." in head of hostname', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc@.aaa';
const output = [TEXT('@abc@.aaa')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "." in tail of hostname', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc@aaa.';
const output = [MENTION('abc', 'aaa', '@abc@aaa'), TEXT('.')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "-" in head of hostname', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc@-aaa';
const output = [TEXT('@abc@-aaa')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow "-" in tail of hostname', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '@abc@aaa-';
const output = [MENTION('abc', 'aaa', '@abc@aaa'), TEXT('-')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-15 06:51:08 +00:00
});
2021-04-03 12:04:53 +00:00
describe('hashtag', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-15 05:50:21 +00:00
const input = '#abc';
const output = [HASHTAG('abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('basic 2', () => {
2021-04-15 04:51:23 +00:00
const input = 'before #abc after';
const output = [TEXT('before '), HASHTAG('abc'), TEXT(' after')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-12-26 18:16:15 +00:00
test('basic non-ascii', () => {
const input = '#äbc';
const output = [HASHTAG('äbc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
test('newlines and whitespace', () => {
const input = 'before #abc\nafter #def\u3000foo #ghi\tbar #jkl';
const output = [
TEXT('before '), HASHTAG('abc'),
TEXT('\nafter '), HASHTAG('def'),
TEXT('\u3000foo '), HASHTAG('ghi'),
TEXT('\tbar '), HASHTAG('jkl'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with keycap number sign', () => {
2021-04-15 04:51:23 +00:00
const input = '#⃣abc123 #abc';
const output = [UNI_EMOJI('#️⃣'), TEXT('abc123 '), HASHTAG('abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with keycap number sign 2', () => {
2021-04-15 04:51:23 +00:00
const input = `abc
#abc`;
const output = [TEXT('abc\n'), UNI_EMOJI('#️⃣'), TEXT('abc')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore a hashtag if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
2021-05-06 15:28:24 +00:00
let input = 'abc#abc';
let output: mfm.MfmNode[] = [TEXT('abc#abc')];
assert.deepStrictEqual(mfm.parse(input), output);
input = 'あいう#abc';
output = [TEXT('あいう'), HASHTAG('abc')];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 07:34:38 +00:00
2023-02-04 00:30:39 +00:00
test('ignore comma and period', () => {
2021-06-05 07:34:38 +00:00
const input = 'Foo #bar, baz #piyo.';
const output = [TEXT('Foo '), HASHTAG('bar'), TEXT(', baz '), HASHTAG('piyo'), TEXT('.')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore exclamation mark', () => {
2021-06-05 07:34:38 +00:00
const input = '#Foo!';
const output = [HASHTAG('Foo'), TEXT('!')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore colon', () => {
2021-06-05 07:34:38 +00:00
const input = '#Foo:';
const output = [HASHTAG('Foo'), TEXT(':')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore single quote', () => {
2021-06-05 07:34:38 +00:00
const input = '#Foo\'';
const output = [HASHTAG('Foo'), TEXT('\'')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore double quote', () => {
2021-06-05 07:34:38 +00:00
const input = '#Foo"';
const output = [HASHTAG('Foo'), TEXT('"')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore square bracket', () => {
2021-06-05 07:34:38 +00:00
const input = '#Foo]';
const output = [HASHTAG('Foo'), TEXT(']')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore slash', () => {
2021-06-05 07:34:38 +00:00
const input = '#foo/bar';
const output = [HASHTAG('foo'), TEXT('/bar')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore angle bracket', () => {
2021-08-28 10:03:01 +00:00
const input = '#foo<bar>';
const output = [HASHTAG('foo'), TEXT('<bar>')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('allow including number', () => {
2021-06-05 07:34:38 +00:00
const input = '#foo123';
const output = [HASHTAG('foo123')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets "()"', () => {
2021-06-05 07:34:38 +00:00
const input = '(#foo)';
const output = [TEXT('('), HASHTAG('foo'), TEXT(')')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets "「」"', () => {
2021-06-05 07:34:38 +00:00
const input = '「#foo」';
const output = [TEXT('「'), HASHTAG('foo'), TEXT('」')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with mixed brackets', () => {
2021-06-05 07:34:38 +00:00
const input = '「#foo(bar)」';
const output = [TEXT('「'), HASHTAG('foo(bar)'), TEXT('」')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets "()" (space before)', () => {
2021-06-05 07:34:38 +00:00
const input = '(bar #foo)';
const output = [TEXT('(bar '), HASHTAG('foo'), TEXT(')')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets "「」" (space before)', () => {
2021-06-05 07:34:38 +00:00
const input = '「bar #foo」';
const output = [TEXT('「bar '), HASHTAG('foo'), TEXT('」')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow number only', () => {
2021-06-05 07:34:38 +00:00
const input = '#123';
const output = [TEXT('#123')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow number only (with brackets)', () => {
2021-06-05 07:34:38 +00:00
const input = '(#123)';
const output = [TEXT('(#123)')];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('url', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://misskey.io/@ai';
const output = [
N_URL('https://misskey.io/@ai'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with other texts', () => {
2021-04-03 12:04:53 +00:00
const input = 'official instance: https://misskey.io/@ai.';
const output = [
TEXT('official instance: '),
N_URL('https://misskey.io/@ai'),
TEXT('.')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2021-06-05 06:56:23 +00:00
2023-02-04 00:30:39 +00:00
test('ignore trailing period', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://misskey.io/@ai.';
const output = [
N_URL('https://misskey.io/@ai'),
TEXT('.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('disallow period only', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = 'https://.';
const output = [
TEXT('https://.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore trailing periods', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://misskey.io/@ai...';
const output = [
N_URL('https://misskey.io/@ai'),
TEXT('...')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with comma', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://example.com/foo?bar=a,b';
const output = [
N_URL('https://example.com/foo?bar=a,b'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore trailing comma', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://example.com/foo, bar';
const output = [
N_URL('https://example.com/foo'),
TEXT(', bar')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://example.com/foo(bar)';
const output = [
N_URL('https://example.com/foo(bar)'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore parent brackets', () => {
2021-06-05 06:56:23 +00:00
const input = '(https://example.com/foo)';
const output = [
TEXT('('),
N_URL('https://example.com/foo'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore parent brackets (2)', () => {
2021-06-05 06:56:23 +00:00
const input = '(foo https://example.com/foo)';
const output = [
TEXT('(foo '),
N_URL('https://example.com/foo'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore parent brackets with internal brackets', () => {
2021-06-05 06:56:23 +00:00
const input = '(https://example.com/foo(bar))';
const output = [
TEXT('('),
N_URL('https://example.com/foo(bar)'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore parent []', () => {
2021-06-05 06:56:23 +00:00
const input = 'foo [https://example.com/foo] bar';
const output = [
TEXT('foo ['),
N_URL('https://example.com/foo'),
TEXT('] bar'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('ignore non-ascii characters contained url without angle brackets', () => {
2021-06-05 06:56:23 +00:00
const input = 'https://大石泉すき.example.com';
const output = [
TEXT('https://大石泉すき.example.com'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('match non-ascii characters contained url with angle brackets', () => {
2021-06-05 06:56:23 +00:00
const input = '<https://大石泉すき.example.com>';
const output = [
2021-07-22 11:30:46 +00:00
N_URL('https://大石泉すき.example.com', true),
2021-06-05 06:56:23 +00:00
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:28:34 +00:00
2023-02-04 00:30:39 +00:00
test('prevent xss', () => {
2023-02-04 00:28:34 +00:00
const input = 'javascript:foo';
const output = [
TEXT('javascript:foo')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('link', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2021-04-03 12:04:53 +00:00
const input = '[official instance](https://misskey.io/@ai).';
const output = [
LINK(false, 'https://misskey.io/@ai', [
TEXT('official instance')
]),
TEXT('.')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('silent flag', () => {
2021-04-03 12:04:53 +00:00
const input = '?[official instance](https://misskey.io/@ai).';
const output = [
LINK(true, 'https://misskey.io/@ai', [
TEXT('official instance')
]),
TEXT('.')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
2023-02-04 00:30:39 +00:00
test('with angle brackets url', () => {
const input = '[official instance](<https://misskey.io/@ai>).';
const output = [
LINK(false, 'https://misskey.io/@ai', [
TEXT('official instance')
]),
TEXT('.')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('prevent xss', () => {
2023-02-04 00:28:34 +00:00
const input = '[click here](javascript:foo)';
const output = [
TEXT('[click here](javascript:foo)')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2022-01-09 09:21:57 +00:00
describe('cannot nest a url in a link label', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2022-01-09 09:21:57 +00:00
const input = 'official instance: [https://misskey.io/@ai](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
TEXT('https://misskey.io/@ai'),
]),
TEXT('.'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('nested', () => {
2022-01-09 09:21:57 +00:00
const input = 'official instance: [https://misskey.io/@ai**https://misskey.io/@ai**](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
TEXT('https://misskey.io/@ai'),
BOLD([
TEXT('https://misskey.io/@ai'),
]),
]),
TEXT('.'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
2022-01-09 09:21:57 +00:00
describe('cannot nest a link in a link label', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2022-01-09 09:21:57 +00:00
const input = 'official instance: [[https://misskey.io/@ai](https://misskey.io/@ai)](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
TEXT('[https://misskey.io/@ai'),
]),
TEXT(']('),
N_URL('https://misskey.io/@ai'),
TEXT(').'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('nested', () => {
2022-01-09 09:21:57 +00:00
const input = 'official instance: [**[https://misskey.io/@ai](https://misskey.io/@ai)**](https://misskey.io/@ai).';
const output = [
TEXT('official instance: '),
LINK(false, 'https://misskey.io/@ai', [
BOLD([
TEXT('[https://misskey.io/@ai](https://misskey.io/@ai)'),
]),
]),
TEXT('.'),
];
});
});
2021-06-05 07:17:56 +00:00
2022-01-09 09:21:57 +00:00
describe('cannot nest a mention in a link label', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
2022-01-09 09:21:57 +00:00
const input = '[@example](https://example.com)';
const output = [
LINK(false, 'https://example.com', [
TEXT('@example'),
]),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('nested', () => {
2022-01-09 09:21:57 +00:00
const input = '[@example**@example**](https://example.com)';
const output = [
LINK(false, 'https://example.com', [
TEXT('@example'),
BOLD([
TEXT('@example'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-06-26 14:16:09 +00:00
});
2023-02-04 00:30:39 +00:00
test('with brackets', () => {
2021-06-05 07:17:56 +00:00
const input = '[foo](https://example.com/foo(bar))';
const output = [
LINK(false, 'https://example.com/foo(bar)', [
TEXT('foo')
]),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with parent brackets', () => {
2021-06-05 07:17:56 +00:00
const input = '([foo](https://example.com/foo(bar)))';
const output = [
TEXT('('),
LINK(false, 'https://example.com/foo(bar)', [
TEXT('foo')
]),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with brackets before', () => {
const input = '[test] foo [bar](https://example.com)';
const output = [
TEXT('[test] foo '),
LINK(false, 'https://example.com', [
TEXT('bar')
]),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
2021-10-01 13:05:11 +00:00
describe('fn', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
const input = '$[tada abc]';
const output = [
FN('tada', { }, [
TEXT('abc')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with a string argument', () => {
const input = '$[spin.speed=1.1s a]';
const output = [
FN('spin', { speed: '1.1s' }, [
TEXT('a')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('with a string argument 2', () => {
2023-01-13 23:59:32 +00:00
const input = '$[position.x=-3 a]';
const output = [
FN('position', { x: '-3' }, [
TEXT('a')
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('invalid fn name', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
const input = '$[関数 text]';
const output = [
TEXT('$[関数 text]')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('nest', () => {
const input = '$[spin.speed=1.1s $[shake a]]';
const output = [
FN('spin', { speed: '1.1s' }, [
FN('shake', { }, [
TEXT('a')
])
])
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2021-04-03 12:04:53 +00:00
});
describe('plain', () => {
2023-02-04 00:30:39 +00:00
test('multiple line', () => {
const input = 'a\n<plain>\n**Hello**\nworld\n</plain>\nb';
const output = [
TEXT('a\n'),
PLAIN('**Hello**\nworld'),
TEXT('\nb')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('single line', () => {
const input = 'a\n<plain>**Hello** world</plain>\nb';
const output = [
TEXT('a\n'),
PLAIN('**Hello** world'),
TEXT('\nb')
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
describe('nesting limit', () => {
describe('quote', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
const input = '>>> abc';
const output = [
QUOTE([
QUOTE([
TEXT('> abc'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('basic 2', () => {
const input = '>> **abc**';
const output = [
QUOTE([
QUOTE([
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
TEXT('**abc**'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
});
2023-02-04 00:30:39 +00:00
test('big', () => {
const input = '<b><b>***abc***</b></b>';
const output = [
BOLD([
BOLD([
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
TEXT('***abc***'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
describe('bold', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
const input = '<i><i>**abc**</i></i>';
const output = [
ITALIC([
ITALIC([
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
TEXT('**abc**'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('tag', () => {
const input = '<i><i><b>abc</b></i></i>';
const output = [
ITALIC([
ITALIC([
TEXT('<b>abc</b>'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
});
2023-02-04 00:30:39 +00:00
test('small', () => {
const input = '<i><i><small>abc</small></i></i>';
const output = [
ITALIC([
ITALIC([
TEXT('<small>abc</small>'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('italic', () => {
const input = '<b><b><i>abc</i></b></b>';
const output = [
BOLD([
BOLD([
TEXT('<i>abc</i>'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
describe('strike', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
const input = '<b><b>~~abc~~</b></b>';
const output = [
BOLD([
BOLD([
TEXT('~~abc~~'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('tag', () => {
const input = '<b><b><s>abc</s></b></b>';
const output = [
BOLD([
BOLD([
TEXT('<s>abc</s>'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
});
describe('hashtag', () => {
2023-02-04 00:30:39 +00:00
test('basic', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
let input, output;
input = '<b>#abc(xyz)</b>';
output = [
BOLD([
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
HASHTAG('abc(xyz)'),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
input = '<b>#abc(x(y)z)</b>';
output = [
BOLD([
HASHTAG('abc'),
TEXT('(x(y)z)'),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('outside "()"', () => {
const input = '(#abc)';
const output = [
TEXT('('),
HASHTAG('abc'),
TEXT(')'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('outside "[]"', () => {
const input = '[#abc]';
const output = [
TEXT('['),
HASHTAG('abc'),
TEXT(']'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('outside "「」"', () => {
const input = '「#abc」';
const output = [
TEXT('「'),
HASHTAG('abc'),
TEXT('」'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
2023-02-04 00:30:39 +00:00
test('outside ""', () => {
const input = '#abc';
const output = [
TEXT(''),
HASHTAG('abc'),
TEXT(''),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});
2023-02-04 00:30:39 +00:00
test('url', () => {
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
let input, output;
input = '<b>https://example.com/abc(xyz)</b>';
output = [
BOLD([
TypeScript版パーサーのマージ (#124) * implement parser with TypeScript (#116) * clean parser * parser, success, failure, str, parser.map * seq * atLeast, any, alt, match, notMatch * mergeText * improve seq * lazy, createLanguage * types * regexp, refactor * nest limit * lint * state * syntaxes * sep1, succeeded, option, fn * simple * strikeWave, plainTag, inlineCode, mathInline * mention, refactor * seqPartial * :rocket: * parser trace * fix mention, implement hashtag * lineBegin, lineEnd, refactor * imple codeBlock, fix lineEnd * codeBlock, mathBlock * fix codeBlock * fix mathBlock * fix codeBlock * lint * fix inlineCode * :rocket: * centerTag * fix nesting limit * fix unicodeEmoji * :rocket: * search * refactor * seqPartial -> seqOrText * lint * url, urlAlt * :rocket: * :rocket: * text * fix * link * linkLabel state * lint * nesting limit for link label * fix url bracket pair * nest * refactor * refactor * remove * add test * wip quote * add quote test * quote * refactor * hashtag * refactor * type * type * refactor * lint * url * italicAsta, italicUnder * italicAsta, italicUnder, mention, rethink spec * rethink spec * test: change implementation-dependent parts * hashtag * add mention test * mention * mention * mention * mention * url * test * hashtag * Revert "Auxiliary commit to revert individual files from 373972beef10eb99ff3e3635a32a207854154a2a" This reverts commit 622b66e20778ad5c283ea7629db853cbf2bb601f. * package-lock * Update tsconfig.json * Update tsconfig.json * ignore a tsd error when importing twemoji-parser regexp * lint * lint Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * v0.23.0-canary.1 * readme * update chagelog * update changelog * update changelog * refactor * update core combinators Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-07-21 17:21:56 +00:00
N_URL('https://example.com/abc(xyz)'),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
input = '<b>https://example.com/abc(x(y)z)</b>';
output = [
BOLD([
N_URL('https://example.com/abc'),
TEXT('(x(y)z)'),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
2023-02-04 00:30:39 +00:00
test('fn', () => {
const input = '<b><b>$[a b]</b></b>';
const output = [
BOLD([
BOLD([
TEXT('$[a b]'),
]),
]),
];
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
});
});
2023-02-04 00:30:39 +00:00
test('composite', () => {
2021-04-03 12:04:53 +00:00
const input =
`before
<center>
2021-10-01 13:05:11 +00:00
Hello $[tada everynyan! 🎉]
2021-04-03 12:04:53 +00:00
I'm @ai, A bot of misskey!
https://github.com/syuilo/ai
</center>
after`;
const output = [
TEXT('before'),
CENTER([
TEXT('Hello '),
FN('tada', { }, [
TEXT('everynyan! '),
UNI_EMOJI('🎉')
]),
TEXT('\n\nI\'m '),
MENTION('ai', null, '@ai'),
TEXT(', A bot of misskey!\n\n'),
N_URL('https://github.com/syuilo/ai')
]),
TEXT('after')
];
2021-04-10 08:31:29 +00:00
assert.deepStrictEqual(mfm.parse(input), output);
2021-04-03 12:04:53 +00:00
});
});