From f916d5bd8f9e8db52c3b6a9c4bfd0bfa8644e257 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 14 Jan 2023 08:56:48 +0900 Subject: [PATCH] remove fnNameList option for more consistency --- docs/api.md | 26 -------------------------- etc/mfm-js.api.md | 1 - src/api.ts | 3 +-- src/internal/index.ts | 2 -- src/internal/parser.ts | 3 --- test/parser.ts | 18 ------------------ 6 files changed, 1 insertion(+), 52 deletions(-) diff --git a/docs/api.md b/docs/api.md index e1fc7d1..619ae54 100644 --- a/docs/api.md +++ b/docs/api.md @@ -9,32 +9,6 @@ console.log(JSON.stringify(nodes)); // => [{"type":"text","props":{"text":"hello "}},{"type":"fn","props":{"name":"tada","args":{}},"children":[{"type":"text","props":{"text":"world"}}]}] ``` -### 利用可能なMFM関数やカスタム絵文字のリストを設定する -MFM関数の名前をホワイトリストに登録して、登録されたMFM関数以外を通常のテキストノードとして解釈するように設定できます。 -デフォルトではすべてのMFM関数名を受け入れるように設定されています。 - -例: -```ts -const nodes = mfm.parse('hello $[tada world]', { fnNameList: ['tada', 'spin'] }); -console.log(JSON.stringify(nodes)); -// => [{"type":"text","props":{"text":"hello "}},{"type":"fn","props":{"name":"tada","args":{}},"children":[{"type":"text","props":{"text":"world"}}]}] -``` - -```ts -const nodes = mfm.parse('hello $[pope world]', { fnNameList: ['tada', 'spin'] }); -console.log(JSON.stringify(nodes)); -// => [{"type":"text","props":{"text":"hello $[pope world]"}}] -``` - -同様に、カスタム絵文字の名前もホワイトリスト制にできます。 - -例: -```ts -const nodes = mfm.parse(':bap:', { emojiCodeList: ['polarbear', 'bap'] }); -console.log(JSON.stringify(nodes)); -// => [{"type":"emojiCode","props":{"name":"bap"}}] -``` - ### 最大のネストの深さを変更する デフォルトで20に設定されています。 diff --git a/etc/mfm-js.api.md b/etc/mfm-js.api.md index 67cd37d..6792d39 100644 --- a/etc/mfm-js.api.md +++ b/etc/mfm-js.api.md @@ -242,7 +242,6 @@ export type NodeType = T extends 'quote' ? MfmQuote : // @public (undocumented) export function parse(input: string, opts?: Partial<{ - fnNameList: string[]; nestLimit: number; }>): MfmNode[]; diff --git a/src/api.ts b/src/api.ts index f3194a8..292d042 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,9 +5,8 @@ import { MfmNode, MfmSimpleNode } from './node'; /** * Generates a MfmNode tree from the MFM string. */ -export function parse(input: string, opts: Partial<{ fnNameList: string[]; nestLimit: number; }> = {}): MfmNode[] { +export function parse(input: string, opts: Partial<{ nestLimit: number; }> = {}): MfmNode[] { const nodes = fullParser(input, { - fnNameList: opts.fnNameList, nestLimit: opts.nestLimit, }); return nodes; diff --git a/src/internal/index.ts b/src/internal/index.ts index 86eb7d8..45138c3 100644 --- a/src/internal/index.ts +++ b/src/internal/index.ts @@ -4,14 +4,12 @@ import { mergeText } from './util'; import * as P from './core'; export type FullParserOpts = { - fnNameList?: string[]; nestLimit?: number; }; export function fullParser(input: string, opts: FullParserOpts): M.MfmNode[] { const result = language.fullParser.handler(input, 0, { nestLimit: (opts.nestLimit != null) ? opts.nestLimit : 20, - fnNameList: opts.fnNameList, depth: 0, linkLabel: false, trace: false, diff --git a/src/internal/parser.ts b/src/internal/parser.ts index 3d1a04f..7327d04 100644 --- a/src/internal/parser.ts +++ b/src/internal/parser.ts @@ -444,9 +444,6 @@ export const language = P.createLanguage({ if (!result.success) { return result; } - if (state.fnNameList != null && !state.fnNameList.includes(result.value)) { - return P.failure(); - } return P.success(result.index, result.value); }); const arg: P.Parser = P.seq([ diff --git a/test/parser.ts b/test/parser.ts index 77a7a41..a7335e0 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -1218,24 +1218,6 @@ hoge`; ]; assert.deepStrictEqual(mfm.parse(input), output); }); - - it('exists name in the fnNameList', () => { - const input = '$[spin.speed=1.1s text]'; - const output = [ - FN('spin', { speed: '1.1s' }, [ - TEXT('text') - ]) - ]; - assert.deepStrictEqual(mfm.parse(input, { fnNameList: ['tada', 'spin'] }), output); - }); - - it('not exists name in the fnNameList', () => { - const input = '$[pope.speed=1.1s text]'; - const output = [ - TEXT('$[pope.speed=1.1s text]') - ]; - assert.deepStrictEqual(mfm.parse(input, { fnNameList: ['tada', 'spin'] }), output); - }); }); describe('plain', () => {