summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-11-03 22:40:12 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-11-03 22:40:12 +0900
commit2e22874dec992f262c40d73fe7dfd8e4bad775f2 (patch)
tree6722b74e8cccc5566be48ee2897faf4cad349e2c
parentAdd missing semicolons (diff)
downloadsharkey-2e22874dec992f262c40d73fe7dfd8e4bad775f2.tar.gz
sharkey-2e22874dec992f262c40d73fe7dfd8e4bad775f2.tar.bz2
sharkey-2e22874dec992f262c40d73fe7dfd8e4bad775f2.zip
Refactoring
-rw-r--r--src/mfm/parse/elements/hashtag.ts4
-rw-r--r--src/mfm/parse/elements/quote.ts4
-rw-r--r--src/mfm/parse/elements/title.ts4
-rw-r--r--src/mfm/parse/index.ts4
4 files changed, 8 insertions, 8 deletions
diff --git a/src/mfm/parse/elements/hashtag.ts b/src/mfm/parse/elements/hashtag.ts
index 95563fe394..7005dbe09b 100644
--- a/src/mfm/parse/elements/hashtag.ts
+++ b/src/mfm/parse/elements/hashtag.ts
@@ -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 ? [{
diff --git a/src/mfm/parse/elements/quote.ts b/src/mfm/parse/elements/quote.ts
index 19e86e6305..5f8c9c7fc6 100644
--- a/src/mfm/parse/elements/quote.ts
+++ b/src/mfm/parse/elements/quote.ts
@@ -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;
diff --git a/src/mfm/parse/elements/title.ts b/src/mfm/parse/elements/title.ts
index c33485e012..c91ed86e69 100644
--- a/src/mfm/parse/elements/title.ts
+++ b/src/mfm/parse/elements/title.ts
@@ -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 {
diff --git a/src/mfm/parse/index.ts b/src/mfm/parse/index.ts
index 99c00ae649..105378343b 100644
--- a/src/mfm/parse/index.ts
+++ b/src/mfm/parse/index.ts
@@ -46,7 +46,7 @@ export type TextElement = { type: 'text', content: string }
| TextElementTitle
| TextElementUrl
| TextElementMotion;
-export type TextElementProcessor = (text: string, i: number) => TextElement | TextElement[];
+export type TextElementProcessor = (text: string, isBegin: boolean) => TextElement | TextElement[];
export default (source: string): TextElement[] => {
if (source == null || source == '') {
@@ -67,7 +67,7 @@ export default (source: string): TextElement[] => {
// パース
while (source != '') {
const parsed = elements.some(el => {
- let _tokens = el(source, i);
+ let _tokens = el(source, i == 0);
if (_tokens) {
if (!Array.isArray(_tokens)) {
_tokens = [_tokens];