mizzkey/src/mfm/parse/elements/title.ts

21 lines
423 B
TypeScript
Raw Normal View History

2018-04-19 15:05:39 +09:00
/**
* Title
*/
2018-06-17 19:55:39 +09:00
export type TextElementTitle = {
2018-06-18 14:28:43 +09:00
type: 'title'
2018-06-17 19:55:39 +09:00
content: string
title: string
};
2018-11-03 15:28:00 +09:00
export default function(text: string, i: number) {
const match = i == 0 ? 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;
}