From 08b431723a3b6b48570dd65c43b1e23355b76e32 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 15 Aug 2018 20:27:49 +0900 Subject: [PATCH] Refactoring --- src/mfm/parse/elements/bold.ts | 2 +- src/mfm/parse/elements/code.ts | 4 ++-- src/mfm/parse/elements/emoji.ts | 4 ++-- src/mfm/parse/elements/quote.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mfm/parse/elements/bold.ts b/src/mfm/parse/elements/bold.ts index cf615cd3cc..c8c3c80a39 100644 --- a/src/mfm/parse/elements/bold.ts +++ b/src/mfm/parse/elements/bold.ts @@ -15,6 +15,6 @@ export default function(text: string) { return { type: 'bold', content: bold, - bold: bold.substr(2, bold.length - 4) + bold: match[1] } as TextElementBold; } diff --git a/src/mfm/parse/elements/code.ts b/src/mfm/parse/elements/code.ts index f48e945048..04ce692ce1 100644 --- a/src/mfm/parse/elements/code.ts +++ b/src/mfm/parse/elements/code.ts @@ -18,7 +18,7 @@ export default function(text: string) { return { type: 'code', content: code, - code: code.substr(3, code.length - 6).trim(), - html: genHtml(code.substr(3, code.length - 6).trim()) + code: match[1], + html: genHtml(match[1]) } as TextElementCode; } diff --git a/src/mfm/parse/elements/emoji.ts b/src/mfm/parse/elements/emoji.ts index 83d3effef5..cd9a3d032c 100644 --- a/src/mfm/parse/elements/emoji.ts +++ b/src/mfm/parse/elements/emoji.ts @@ -9,12 +9,12 @@ export type TextElementEmoji = { }; export default function(text: string) { - const match = text.match(/^:[a-zA-Z0-9+-_]+:/); + const match = text.match(/^:([a-zA-Z0-9+-_]+):/); if (!match) return null; const emoji = match[0]; return { type: 'emoji', content: emoji, - emoji: emoji.substr(1, emoji.length - 2) + emoji: match[1] } as TextElementEmoji; } diff --git a/src/mfm/parse/elements/quote.ts b/src/mfm/parse/elements/quote.ts index bef9ad4988..ea99240d5f 100644 --- a/src/mfm/parse/elements/quote.ts +++ b/src/mfm/parse/elements/quote.ts @@ -15,6 +15,6 @@ export default function(text: string) { return { type: 'quote', content: quote, - quote: quote.substr(1, quote.length - 2).trim(), + quote: match[1].trim(), } as TextElementQuote; }