iceshrimp-legacy/src/mfm/parse/elements/title.ts
2018-11-16 21:57:19 +09:00

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