2021-04-03 12:04:53 +00:00
|
|
|
|
import assert from 'assert';
|
2021-04-10 08:31:29 +00:00
|
|
|
|
import * as mfm from '../built/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
|
2021-04-10 09:09:44 +00:00
|
|
|
|
} from '../built/index';
|
2021-04-03 12:04:53 +00:00
|
|
|
|
|
2021-04-15 04:51:23 +00:00
|
|
|
|
describe('PlainParser', () => {
|
|
|
|
|
describe('text', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const input = 'abc';
|
|
|
|
|
const output = [TEXT('abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parsePlain(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore hashtag', () => {
|
|
|
|
|
const input = 'abc#abc';
|
|
|
|
|
const output = [TEXT('abc#abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parsePlain(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('keycap number sign', () => {
|
|
|
|
|
const input = 'abc#️⃣abc';
|
|
|
|
|
const output = [TEXT('abc'), UNI_EMOJI('#️⃣'), TEXT('abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parsePlain(input), output);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('FullParser', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
describe('text', () => {
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('普通のテキストを入力すると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', () => {
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('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
|
|
|
|
});
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('複数行の引用ブロックを使用できる', () => {
|
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
|
|
|
|
});
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('引用ブロックはブロックをネストできる', () => {
|
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
|
|
|
|
});
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('引用ブロックはインライン構文を含んだブロックをネストできる', () => {
|
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
|
|
|
|
});
|
2021-04-17 06:35:07 +00:00
|
|
|
|
it('複数行の引用ブロックでは空行を含めることができる', () => {
|
|
|
|
|
const input = `
|
|
|
|
|
> abc
|
|
|
|
|
>
|
|
|
|
|
> 123
|
|
|
|
|
`;
|
|
|
|
|
const output = [
|
|
|
|
|
QUOTE([
|
|
|
|
|
TEXT('abc\n\n123')
|
|
|
|
|
])
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
it('1行の引用ブロックを空行にはできない', () => {
|
|
|
|
|
const input = `> `;
|
|
|
|
|
const output = [
|
|
|
|
|
TEXT('> ')
|
|
|
|
|
];
|
|
|
|
|
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('検索構文を使用できる', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
it('Search', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('[Search]', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('search', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('[search]', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('検索', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('[検索]', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
});
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('ブロックの前後にあるテキストが正しく解釈される', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
const input = 'abc\nhoge piyo bebeyo 検索\n123';
|
|
|
|
|
const output = [
|
|
|
|
|
TEXT('abc'),
|
|
|
|
|
SEARCH('hoge piyo bebeyo', 'hoge piyo bebeyo 検索'),
|
|
|
|
|
TEXT('123')
|
|
|
|
|
];
|
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', () => {
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('コードブロックを使用できる', () => {
|
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-04-03 12:34:08 +00:00
|
|
|
|
it('コードブロックには複数行のコードを入力できる', () => {
|
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-04-03 12:34:08 +00:00
|
|
|
|
it('コードブロックは言語を指定できる', () => {
|
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-04-03 12:34:08 +00:00
|
|
|
|
it('ブロックの前後にあるテキストが正しく解釈される', () => {
|
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
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('mathBlock', () => {
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('1行の数式ブロックを使用できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('ブロックの前後にあるテキストが正しく解釈される', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('行末以外に閉じタグがある場合はマッチしない', () => {
|
|
|
|
|
const input = '\\[aaa\\]after';
|
|
|
|
|
const output = [
|
|
|
|
|
TEXT('\\[aaa\\]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
|
|
|
|
});
|
2021-04-03 12:34:08 +00:00
|
|
|
|
it('行頭以外に開始タグがある場合はマッチしない', () => {
|
|
|
|
|
const input = 'before\\[aaa\\]';
|
2021-04-03 12:04:53 +00:00
|
|
|
|
const output = [
|
2021-04-03 12:34:08 +00:00
|
|
|
|
TEXT('before\\[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', () => {
|
|
|
|
|
it('single text', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('multiple text', () => {
|
|
|
|
|
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', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
it('keycap number sign', () => {
|
|
|
|
|
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', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容にはインライン構文を利用できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容は改行できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('bold', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容にはインライン構文を利用できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容は改行できる', () => {
|
|
|
|
|
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', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容にはインライン構文を利用できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容は改行できる', () => {
|
|
|
|
|
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', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容にはインライン構文を利用できる', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
it('内容は改行できる', () => {
|
|
|
|
|
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', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
it('basic 2', () => {
|
|
|
|
|
const input = 'before *abc* after';
|
|
|
|
|
const output = [
|
|
|
|
|
TEXT('before '),
|
|
|
|
|
ITALIC([
|
|
|
|
|
TEXT('abc')
|
|
|
|
|
]),
|
|
|
|
|
TEXT(' after')
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-06 15:28:24 +00:00
|
|
|
|
it('ignore a italic syntax if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
|
|
|
|
|
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', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const input = '_abc_';
|
|
|
|
|
const output = [
|
|
|
|
|
ITALIC([
|
|
|
|
|
TEXT('abc')
|
|
|
|
|
])
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('basic 2', () => {
|
|
|
|
|
const input = 'before _abc_ after';
|
|
|
|
|
const output = [
|
|
|
|
|
TEXT('before '),
|
|
|
|
|
ITALIC([
|
|
|
|
|
TEXT('abc')
|
|
|
|
|
]),
|
|
|
|
|
TEXT(' after')
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-06 15:28:24 +00:00
|
|
|
|
it('ignore a italic syntax if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// strike
|
|
|
|
|
|
|
|
|
|
// inlineCode
|
|
|
|
|
|
|
|
|
|
// mathInline
|
|
|
|
|
|
2021-04-15 06:51:08 +00:00
|
|
|
|
describe('mention', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const input = '@abc';
|
|
|
|
|
const output = [MENTION('abc', null, '@abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('basic 2', () => {
|
|
|
|
|
const input = 'before @abc after';
|
|
|
|
|
const output = [TEXT('before '), MENTION('abc', null, '@abc'), TEXT(' after')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('basic remote', () => {
|
|
|
|
|
const input = '@abc@misskey.io';
|
|
|
|
|
const output = [MENTION('abc', 'misskey.io', '@abc@misskey.io')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('basic remote 2', () => {
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('basic remote 3', () => {
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('ignore format of mail address', () => {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
it('detect as a mention if the before char is [^a-z0-9]i', () => {
|
|
|
|
|
const input = 'あいう@abc';
|
|
|
|
|
const output = [TEXT('あいう'), MENTION('abc', null, '@abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
2021-04-15 06:51:08 +00:00
|
|
|
|
});
|
2021-04-03 12:04:53 +00:00
|
|
|
|
|
|
|
|
|
describe('hashtag', () => {
|
2021-04-15 04:51:23 +00:00
|
|
|
|
it('basic', () => {
|
2021-04-15 05:50:21 +00:00
|
|
|
|
const input = '#abc';
|
|
|
|
|
const output = [HASHTAG('abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with keycap number sign', () => {
|
|
|
|
|
const input = '#️⃣abc123 #abc';
|
|
|
|
|
const output = [UNI_EMOJI('#️⃣'), TEXT('abc123 '), HASHTAG('abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('with keycap number sign 2', () => {
|
|
|
|
|
const input = `abc
|
|
|
|
|
#️⃣abc`;
|
|
|
|
|
const output = [TEXT('abc\n'), UNI_EMOJI('#️⃣'), TEXT('abc')];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-06 15:28:24 +00:00
|
|
|
|
it('ignore a hashtag if the before char is neither a space nor an LF nor [^a-z0-9]i', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('url', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('link', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('silent flag', () => {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('do not yield url node even if label is recognisable as a url', () => {
|
|
|
|
|
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('.')
|
|
|
|
|
];
|
2021-04-10 08:31:29 +00:00
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
2021-04-03 12:04:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-24 04:32:55 +00:00
|
|
|
|
// disabled
|
|
|
|
|
// it('do not yield link node even if label is recognisable as a link', () => {
|
|
|
|
|
// 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](https://misskey.io/@ai)')
|
|
|
|
|
// ]),
|
|
|
|
|
// TEXT('.')
|
|
|
|
|
// ];
|
|
|
|
|
// assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
// });
|
2021-04-03 12:04:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 05:38:15 +00:00
|
|
|
|
describe('fn v1', () => {
|
2021-04-03 12:04:53 +00:00
|
|
|
|
it('basic', () => {
|
|
|
|
|
const input = '[tada 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
|
|
|
|
});
|
2021-04-14 15:03:09 +00:00
|
|
|
|
|
|
|
|
|
it('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);
|
|
|
|
|
});
|
2021-04-18 05:38:15 +00:00
|
|
|
|
|
2021-04-24 04:32:55 +00:00
|
|
|
|
// fn nest is disabled
|
|
|
|
|
// it('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-18 05:38:15 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('fn v2', () => {
|
|
|
|
|
it('basic', () => {
|
|
|
|
|
const input = '$[tada abc]';
|
|
|
|
|
const output = [
|
|
|
|
|
FN('tada', { }, [
|
|
|
|
|
TEXT('abc')
|
|
|
|
|
])
|
|
|
|
|
];
|
|
|
|
|
assert.deepStrictEqual(mfm.parse(input), output);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('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);
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-24 04:32:55 +00:00
|
|
|
|
// fn nest is disabled
|
|
|
|
|
// it('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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('composite', () => {
|
|
|
|
|
const input =
|
|
|
|
|
`before
|
|
|
|
|
<center>
|
|
|
|
|
Hello [tada everynyan! 🎉]
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
});
|