Refactoring

This commit is contained in:
syuilo 2018-11-03 22:40:12 +09:00
parent 30f0b1c30d
commit 2e22874dec
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
4 changed files with 8 additions and 8 deletions

View file

@ -8,8 +8,8 @@ export type TextElementHashtag = {
hashtag: string;
};
export default function(text: string, i: number) {
if (!(/^\s#[^\s\.,!\?#]+/.test(text) || (i == 0 && /^#[^\s\.,!\?#]+/.test(text)))) return null;
export default function(text: string, isBegin: boolean) {
if (!(/^\s#[^\s\.,!\?#]+/.test(text) || (isBegin && /^#[^\s\.,!\?#]+/.test(text)))) return null;
const isHead = text.startsWith('#');
const hashtag = text.match(/^\s?#[^\s\.,!\?#]+/)[0];
const res: any[] = !isHead ? [{

View file

@ -8,9 +8,9 @@ export type TextElementQuote = {
quote: string;
};
export default function(text: string, index: number) {
export default function(text: string, isBegin: boolean) {
const match = text.match(/^"([\s\S]+?)\n"/) || text.match(/^\n>([\s\S]+?)(\n\n|$)/) ||
(index == 0 ? text.match(/^>([\s\S]+?)(\n\n|$)/) : null);
(isBegin ? text.match(/^>([\s\S]+?)(\n\n|$)/) : null);
if (!match) return null;

View file

@ -8,8 +8,8 @@ export type TextElementTitle = {
title: string;
};
export default function(text: string, i: number) {
const match = i == 0 ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
export default function(text: string, isBegin: boolean) {
const match = isBegin ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
if (!match) return null;
const title = match[0];
return {