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

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

export default function(text: string, before: string) {
	const isBegin = before == '';

	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;
}