0ff390ed80
Resolve #2779 Resolve #3053
22 lines
417 B
TypeScript
22 lines
417 B
TypeScript
/**
|
|
* 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;
|
|
}
|