2018-04-19 15:05:39 +09:00
|
|
|
/**
|
|
|
|
|
* Title
|
|
|
|
|
*/
|
|
|
|
|
|
2018-06-17 19:55:39 +09:00
|
|
|
export type TextElementTitle = {
|
2018-11-03 22:38:12 +09:00
|
|
|
type: 'title';
|
|
|
|
|
content: string;
|
|
|
|
|
title: string;
|
2018-06-17 19:55:39 +09:00
|
|
|
};
|
|
|
|
|
|
2018-11-03 22:40:12 +09:00
|
|
|
export default function(text: string, isBegin: boolean) {
|
|
|
|
|
const match = isBegin ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
|
2018-04-19 15:05:39 +09:00
|
|
|
if (!match) return null;
|
|
|
|
|
const title = match[0];
|
|
|
|
|
return {
|
|
|
|
|
type: 'title',
|
|
|
|
|
content: title,
|
|
|
|
|
title: title.substr(1, title.length - 3)
|
2018-06-17 19:55:39 +09:00
|
|
|
} as TextElementTitle;
|
|
|
|
|
}
|