mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-25 15:35:13 +00:00
parent
11fefdffe0
commit
2a3498b8f2
4 changed files with 3 additions and 17 deletions
|
@ -243,7 +243,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[];
|
fnNameList: string[];
|
||||||
emojiCodeList: string[];
|
|
||||||
nestLimit: number;
|
nestLimit: number;
|
||||||
}>): MfmNode[];
|
}>): MfmNode[];
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ 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[]; emojiCodeList: string[]; nestLimit: number; }> = {}): MfmNode[] {
|
export function parse(input: string, opts: Partial<{ fnNameList: string[]; nestLimit: number; }> = {}): MfmNode[] {
|
||||||
const nodes = fullParser(input, {
|
const nodes = fullParser(input, {
|
||||||
fnNameList: opts.fnNameList,
|
fnNameList: opts.fnNameList,
|
||||||
emojiCodeList: opts.emojiCodeList,
|
|
||||||
nestLimit: opts.nestLimit,
|
nestLimit: opts.nestLimit,
|
||||||
});
|
});
|
||||||
return nodes;
|
return nodes;
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as P from './core';
|
||||||
|
|
||||||
export type FullParserOpts = {
|
export type FullParserOpts = {
|
||||||
fnNameList?: string[];
|
fnNameList?: string[];
|
||||||
emojiCodeList?: string[];
|
|
||||||
nestLimit?: number;
|
nestLimit?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ 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,
|
fnNameList: opts.fnNameList,
|
||||||
emojiCodeList: opts.emojiCodeList,
|
|
||||||
depth: 0,
|
depth: 0,
|
||||||
linkLabel: false,
|
linkLabel: false,
|
||||||
trace: false,
|
trace: false,
|
||||||
|
|
|
@ -628,23 +628,13 @@ export const language = P.createLanguage({
|
||||||
emojiCode: r => {
|
emojiCode: r => {
|
||||||
const side = P.notMatch(P.regexp(/[a-z0-9]/i));
|
const side = P.notMatch(P.regexp(/[a-z0-9]/i));
|
||||||
const mark = P.str(':');
|
const mark = P.str(':');
|
||||||
const parser = P.seq([
|
return P.seq([
|
||||||
P.alt([P.lineBegin, side]),
|
P.alt([P.lineBegin, side]),
|
||||||
mark,
|
mark,
|
||||||
P.regexp(/[a-z0-9_+-]+/i),
|
P.regexp(/[a-z0-9_+-]+/i),
|
||||||
mark,
|
mark,
|
||||||
P.alt([P.lineEnd, side]),
|
P.alt([P.lineEnd, side]),
|
||||||
], 2);
|
], 2).map(name => M.EMOJI_CODE(name as string));
|
||||||
return new P.Parser((input, index, state) => {
|
|
||||||
const result = parser.handler(input, index, state);
|
|
||||||
if (!result.success) {
|
|
||||||
return P.failure();
|
|
||||||
}
|
|
||||||
if (state.emojiCodeList != null && !state.emojiCodeList.includes(result.value)) {
|
|
||||||
return P.failure();
|
|
||||||
}
|
|
||||||
return P.success(result.index, M.EMOJI_CODE(result.value as string));
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
link: r => {
|
link: r => {
|
||||||
|
|
Loading…
Reference in a new issue