summaryrefslogtreecommitdiff
path: root/src/mfm/parse/elements/title.ts
blob: d67236aa783925d342b9c9b21bc786812a385717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Title
 */

export type TextElementTitle = {
	type: 'title';
	content: string;
	title: string;
};

export default function(text: string, isBegin: boolean) {
	const match = isBegin ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
	if (!match) return null;
	return {
		type: 'title',
		content: match[0],
		title: match[2]
	} as TextElementTitle;
}