diff options
Diffstat (limited to 'src/text/parse/elements')
| -rw-r--r-- | src/text/parse/elements/bold.ts | 12 | ||||
| -rw-r--r-- | src/text/parse/elements/code.ts | 13 | ||||
| -rw-r--r-- | src/text/parse/elements/emoji.ts | 12 | ||||
| -rw-r--r-- | src/text/parse/elements/hashtag.ts | 12 | ||||
| -rw-r--r-- | src/text/parse/elements/inline-code.ts | 13 | ||||
| -rw-r--r-- | src/text/parse/elements/link.ts | 14 | ||||
| -rw-r--r-- | src/text/parse/elements/mention.ts | 13 | ||||
| -rw-r--r-- | src/text/parse/elements/quote.ts | 12 | ||||
| -rw-r--r-- | src/text/parse/elements/search.ts | 10 | ||||
| -rw-r--r-- | src/text/parse/elements/title.ts | 12 | ||||
| -rw-r--r-- | src/text/parse/elements/url.ts | 12 |
11 files changed, 103 insertions, 32 deletions
diff --git a/src/text/parse/elements/bold.ts b/src/text/parse/elements/bold.ts index ce25764457..0566ace8b7 100644 --- a/src/text/parse/elements/bold.ts +++ b/src/text/parse/elements/bold.ts @@ -2,7 +2,13 @@ * Bold */ -module.exports = text => { +export type TextElementBold = { + type: "bold" + content: string + bold: string +}; + +export default function(text: string) { const match = text.match(/^\*\*(.+?)\*\*/); if (!match) return null; const bold = match[0]; @@ -10,5 +16,5 @@ module.exports = text => { type: 'bold', content: bold, bold: bold.substr(2, bold.length - 4) - }; -}; + } as TextElementBold; +} diff --git a/src/text/parse/elements/code.ts b/src/text/parse/elements/code.ts index 4821e95fe2..de87aa410b 100644 --- a/src/text/parse/elements/code.ts +++ b/src/text/parse/elements/code.ts @@ -4,7 +4,14 @@ import genHtml from '../core/syntax-highlighter'; -module.exports = text => { +export type TextElementCode = { + type: "code" + content: string + code: string + html: string +}; + +export default function(text: string) { const match = text.match(/^```([\s\S]+?)```/); if (!match) return null; const code = match[0]; @@ -13,5 +20,5 @@ module.exports = text => { content: code, code: code.substr(3, code.length - 6).trim(), html: genHtml(code.substr(3, code.length - 6).trim()) - }; -}; + } as TextElementCode; +} diff --git a/src/text/parse/elements/emoji.ts b/src/text/parse/elements/emoji.ts index e24231a223..d0eed88965 100644 --- a/src/text/parse/elements/emoji.ts +++ b/src/text/parse/elements/emoji.ts @@ -2,7 +2,13 @@ * Emoji */ -module.exports = text => { +export type TextElementEmoji = { + type: "emoji" + content: string + emoji: string +}; + +export default function(text: string) { const match = text.match(/^:[a-zA-Z0-9+-_]+:/); if (!match) return null; const emoji = match[0]; @@ -10,5 +16,5 @@ module.exports = text => { type: 'emoji', content: emoji, emoji: emoji.substr(1, emoji.length - 2) - }; -}; + } as TextElementEmoji; +} diff --git a/src/text/parse/elements/hashtag.ts b/src/text/parse/elements/hashtag.ts index ee57b140b8..cde0c2b224 100644 --- a/src/text/parse/elements/hashtag.ts +++ b/src/text/parse/elements/hashtag.ts @@ -2,7 +2,13 @@ * Hashtag */ -module.exports = (text, i) => { +export type TextElementHashtag = { + type: "hashtag" + content: string + hashtag: string +}; + +export default function(text: string, i: number) { if (!(/^\s#[^\s]+/.test(text) || (i == 0 && /^#[^\s]+/.test(text)))) return null; const isHead = text[0] == '#'; const hashtag = text.match(/^\s?#[^\s]+/)[0]; @@ -15,5 +21,5 @@ module.exports = (text, i) => { content: isHead ? hashtag : hashtag.substr(1), hashtag: isHead ? hashtag.substr(1) : hashtag.substr(2) }); - return res; -}; + return res as TextElementHashtag[]; +} diff --git a/src/text/parse/elements/inline-code.ts b/src/text/parse/elements/inline-code.ts index 9f9ef51a2b..bcb0bca0ad 100644 --- a/src/text/parse/elements/inline-code.ts +++ b/src/text/parse/elements/inline-code.ts @@ -4,7 +4,14 @@ import genHtml from '../core/syntax-highlighter'; -module.exports = text => { +export type TextElementInlineCode = { + type: "inline-code" + content: string + code: string + html: string +}; + +export default function(text: string) { const match = text.match(/^`(.+?)`/); if (!match) return null; const code = match[0]; @@ -13,5 +20,5 @@ module.exports = text => { content: code, code: code.substr(1, code.length - 2).trim(), html: genHtml(code.substr(1, code.length - 2).trim()) - }; -}; + } as TextElementInlineCode; +} diff --git a/src/text/parse/elements/link.ts b/src/text/parse/elements/link.ts index 35563ddc3d..7e0d6f5cf8 100644 --- a/src/text/parse/elements/link.ts +++ b/src/text/parse/elements/link.ts @@ -2,7 +2,15 @@ * Link */ -module.exports = text => { +export type TextElementLink = { + type: "link" + content: string + title: string + url: string + silent: boolean +}; + +export default function(text: string) { const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/); if (!match) return null; const silent = text[0] == '?'; @@ -15,5 +23,5 @@ module.exports = text => { title: title, url: url, silent: silent - }; -}; + } as TextElementLink; +} diff --git a/src/text/parse/elements/mention.ts b/src/text/parse/elements/mention.ts index 2ad2788300..a4140458d4 100644 --- a/src/text/parse/elements/mention.ts +++ b/src/text/parse/elements/mention.ts @@ -3,7 +3,14 @@ */ import parseAcct from '../../../acct/parse'; -module.exports = text => { +export type TextElementMention = { + type: "mention" + content: string + username: string + host: string +}; + +export default function(text: string) { const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i); if (!match) return null; const mention = match[0]; @@ -13,5 +20,5 @@ module.exports = text => { content: mention, username, host - }; -}; + } as TextElementMention; +} diff --git a/src/text/parse/elements/quote.ts b/src/text/parse/elements/quote.ts index cc8cfffdc4..56de561f3f 100644 --- a/src/text/parse/elements/quote.ts +++ b/src/text/parse/elements/quote.ts @@ -2,7 +2,13 @@ * Quoted text */ -module.exports = text => { +export type TextElementQuote = { + type: "quote" + content: string + quote: string +}; + +export default function(text: string) { const match = text.match(/^"([\s\S]+?)\n"/); if (!match) return null; const quote = match[0]; @@ -10,5 +16,5 @@ module.exports = text => { type: 'quote', content: quote, quote: quote.substr(1, quote.length - 2).trim(), - }; -}; + } as TextElementQuote; +} diff --git a/src/text/parse/elements/search.ts b/src/text/parse/elements/search.ts index 12ee8ecbb8..4bd19ee3fa 100644 --- a/src/text/parse/elements/search.ts +++ b/src/text/parse/elements/search.ts @@ -2,7 +2,13 @@ * Search */ -module.exports = text => { +export type TextElementSearch = { + type: "search" + content: string + query: string +}; + +export default function(text: string) { const match = text.match(/^(.+?) 検索(\n|$)/); if (!match) return null; return { @@ -10,4 +16,4 @@ module.exports = text => { content: match[0], query: match[1] }; -}; +} diff --git a/src/text/parse/elements/title.ts b/src/text/parse/elements/title.ts index 9f4708f5d6..11b3abc61b 100644 --- a/src/text/parse/elements/title.ts +++ b/src/text/parse/elements/title.ts @@ -2,7 +2,13 @@ * Title */ -module.exports = text => { +export type TextElementTitle = { + type: "title" + content: string + title: string +}; + +export default function(text: string) { const match = text.match(/^【(.+?)】\n/); if (!match) return null; const title = match[0]; @@ -10,5 +16,5 @@ module.exports = text => { type: 'title', content: title, title: title.substr(1, title.length - 3) - }; -}; + } as TextElementTitle; +} diff --git a/src/text/parse/elements/url.ts b/src/text/parse/elements/url.ts index 1003aff9c3..bbc27b4fd7 100644 --- a/src/text/parse/elements/url.ts +++ b/src/text/parse/elements/url.ts @@ -2,7 +2,13 @@ * URL */ -module.exports = text => { +export type TextElementUrl = { + type: "url" + content: string + url: string +}; + +export default function(text: string) { const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/); if (!match) return null; const url = match[0]; @@ -10,5 +16,5 @@ module.exports = text => { type: 'url', content: url, url: url - }; -}; + } as TextElementUrl; +} |