mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-22 05:55:13 +00:00
remove fnNameList option for more consistency
This commit is contained in:
parent
2a3498b8f2
commit
f916d5bd8f
6 changed files with 1 additions and 52 deletions
26
docs/api.md
26
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"}}]}]
|
// => [{"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に設定されています。
|
デフォルトで20に設定されています。
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,6 @@ export type NodeType<T extends MfmNode['type']> = T extends 'quote' ? MfmQuote :
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export function parse(input: string, opts?: Partial<{
|
export function parse(input: string, opts?: Partial<{
|
||||||
fnNameList: string[];
|
|
||||||
nestLimit: number;
|
nestLimit: number;
|
||||||
}>): MfmNode[];
|
}>): MfmNode[];
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,8 @@ import { MfmNode, MfmSimpleNode } from './node';
|
||||||
/**
|
/**
|
||||||
* Generates a MfmNode tree from the MFM string.
|
* 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, {
|
const nodes = fullParser(input, {
|
||||||
fnNameList: opts.fnNameList,
|
|
||||||
nestLimit: opts.nestLimit,
|
nestLimit: opts.nestLimit,
|
||||||
});
|
});
|
||||||
return nodes;
|
return nodes;
|
||||||
|
|
|
@ -4,14 +4,12 @@ import { mergeText } from './util';
|
||||||
import * as P from './core';
|
import * as P from './core';
|
||||||
|
|
||||||
export type FullParserOpts = {
|
export type FullParserOpts = {
|
||||||
fnNameList?: string[];
|
|
||||||
nestLimit?: number;
|
nestLimit?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function fullParser(input: string, opts: FullParserOpts): M.MfmNode[] {
|
export function fullParser(input: string, opts: FullParserOpts): M.MfmNode[] {
|
||||||
const result = language.fullParser.handler(input, 0, {
|
const result = language.fullParser.handler(input, 0, {
|
||||||
nestLimit: (opts.nestLimit != null) ? opts.nestLimit : 20,
|
nestLimit: (opts.nestLimit != null) ? opts.nestLimit : 20,
|
||||||
fnNameList: opts.fnNameList,
|
|
||||||
depth: 0,
|
depth: 0,
|
||||||
linkLabel: false,
|
linkLabel: false,
|
||||||
trace: false,
|
trace: false,
|
||||||
|
|
|
@ -444,9 +444,6 @@ export const language = P.createLanguage({
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (state.fnNameList != null && !state.fnNameList.includes(result.value)) {
|
|
||||||
return P.failure();
|
|
||||||
}
|
|
||||||
return P.success(result.index, result.value);
|
return P.success(result.index, result.value);
|
||||||
});
|
});
|
||||||
const arg: P.Parser<ArgPair> = P.seq([
|
const arg: P.Parser<ArgPair> = P.seq([
|
||||||
|
|
|
@ -1218,24 +1218,6 @@ hoge`;
|
||||||
];
|
];
|
||||||
assert.deepStrictEqual(mfm.parse(input), output);
|
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', () => {
|
describe('plain', () => {
|
||||||
|
|
Loading…
Reference in a new issue