Refactoring
This commit is contained in:
parent
30f0b1c30d
commit
2e22874dec
@ -8,8 +8,8 @@ export type TextElementHashtag = {
|
|||||||
hashtag: string;
|
hashtag: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function(text: string, i: number) {
|
export default function(text: string, isBegin: boolean) {
|
||||||
if (!(/^\s#[^\s\.,!\?#]+/.test(text) || (i == 0 && /^#[^\s\.,!\?#]+/.test(text)))) return null;
|
if (!(/^\s#[^\s\.,!\?#]+/.test(text) || (isBegin && /^#[^\s\.,!\?#]+/.test(text)))) return null;
|
||||||
const isHead = text.startsWith('#');
|
const isHead = text.startsWith('#');
|
||||||
const hashtag = text.match(/^\s?#[^\s\.,!\?#]+/)[0];
|
const hashtag = text.match(/^\s?#[^\s\.,!\?#]+/)[0];
|
||||||
const res: any[] = !isHead ? [{
|
const res: any[] = !isHead ? [{
|
||||||
|
@ -8,9 +8,9 @@ export type TextElementQuote = {
|
|||||||
quote: string;
|
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|$)/) ||
|
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;
|
if (!match) return null;
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ export type TextElementTitle = {
|
|||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function(text: string, i: number) {
|
export default function(text: string, isBegin: boolean) {
|
||||||
const match = i == 0 ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
|
const match = isBegin ? text.match(/^(【|\[)(.+?)(】|])\n/) : text.match(/^\n(【|\[)(.+?)(】|])\n/);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const title = match[0];
|
const title = match[0];
|
||||||
return {
|
return {
|
||||||
|
@ -46,7 +46,7 @@ export type TextElement = { type: 'text', content: string }
|
|||||||
| TextElementTitle
|
| TextElementTitle
|
||||||
| TextElementUrl
|
| TextElementUrl
|
||||||
| TextElementMotion;
|
| TextElementMotion;
|
||||||
export type TextElementProcessor = (text: string, i: number) => TextElement | TextElement[];
|
export type TextElementProcessor = (text: string, isBegin: boolean) => TextElement | TextElement[];
|
||||||
|
|
||||||
export default (source: string): TextElement[] => {
|
export default (source: string): TextElement[] => {
|
||||||
if (source == null || source == '') {
|
if (source == null || source == '') {
|
||||||
@ -67,7 +67,7 @@ export default (source: string): TextElement[] => {
|
|||||||
// パース
|
// パース
|
||||||
while (source != '') {
|
while (source != '') {
|
||||||
const parsed = elements.some(el => {
|
const parsed = elements.some(el => {
|
||||||
let _tokens = el(source, i);
|
let _tokens = el(source, i == 0);
|
||||||
if (_tokens) {
|
if (_tokens) {
|
||||||
if (!Array.isArray(_tokens)) {
|
if (!Array.isArray(_tokens)) {
|
||||||
_tokens = [_tokens];
|
_tokens = [_tokens];
|
||||||
|
Loading…
Reference in New Issue
Block a user