Skip to content
Snippets Groups Projects
node.ts 2.38 KiB
Newer Older
export type MfmNode = MfmBlock | MfmInline;

export type MfmBlock = MfmQuote | MfmSearch | MfmCodeBlock | MfmMathBlock | MfmCenter;

marihachi's avatar
marihachi committed
const blockTypes: MfmNode['type'][] = [ 'quote', 'search', 'blockCode', 'mathBlock', 'center' ];
export function isMfmBlock(node: MfmNode): node is MfmBlock {
	return blockTypes.includes(node.type);
}

export type MfmQuote = {
	type: 'quote';
	children: MfmNode[];
};

export type MfmSearch = {
	type: 'search';
	props: {
		query: string;
		content: string;
	};
};

export type MfmCodeBlock = {
	type: 'blockCode';
	props: {
		code: string;
		lang: string | null;
	};
};

export type MfmMathBlock = {
	type: 'mathBlock';
	props: {
		formula: string;
	};
};

export type MfmCenter = {
	type: 'center';
marihachi's avatar
marihachi committed
	children: MfmInline[];
marihachi's avatar
marihachi committed
export type MfmInline = MfmUnicodeEmoji | MfmEmojiCode | MfmBold | MfmSmall | MfmItalic | MfmStrike |
	MfmInlineCode | MfmMathInline | MfmMention | MfmHashtag | MfmUrl | MfmLink | MfmFn | MfmText;
export type MfmUnicodeEmoji = {
	type: 'unicodeEmoji';
marihachi's avatar
marihachi committed
	props: {
marihachi's avatar
marihachi committed
	};
marihachi's avatar
marihachi committed
export type MfmEmojiCode = {
	type: 'emojiCode';
	props: {
		name: string;
	};
	children?: [];
};

export type MfmBold = {
	type: 'bold';
	children: MfmInline[];
};

export type MfmSmall = {
	type: 'small';
	children: MfmInline[];
};

export type MfmItalic = {
	type: 'italic';
	children: MfmInline[];
};

export type MfmStrike = {
	type: 'strike';
	children: MfmInline[];
};

export type MfmInlineCode = {
	type: 'inlineCode';
	props: {
		code: string;
	};
};

export type MfmMathInline = {
	type: 'mathInline';
	props: {
		formula: string;
	};
};

export type MfmMention = {
	type: 'mention';
	props: {
		username: string;
		host: string | null;
		acct: string;
	};
};

export type MfmHashtag = {
	type: 'hashtag';
	props: {
		hashtag: string;
	};
};

export type MfmUrl = {
	type: 'url';
	props: {
		url: string;
	};
};

export type MfmLink = {
	type: 'link';
	props: {
		silent: boolean;
		url: string;
	};
	children: MfmInline[];
};

export type MfmFn = {
	type: 'fn';
	props: {
		name: string;
		args: Record<string, string | true>;
	};
	children: MfmInline[];
};

export type MfmText = {
	type: 'text';
	props: {
		text: string;
	};