diff options
| author | marihachi <marihachi0620@gmail.com> | 2021-04-11 00:18:29 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-11 00:18:29 +0900 |
| commit | 1ec3338d2e0a0286a86d766bce3edc87e8c9a158 (patch) | |
| tree | faa0aa3be4e959eb215a2e6e800cb96b137b55da /src | |
| parent | Tweak UI (diff) | |
| download | misskey-1ec3338d2e0a0286a86d766bce3edc87e8c9a158.tar.gz misskey-1ec3338d2e0a0286a86d766bce3edc87e8c9a158.tar.bz2 misskey-1ec3338d2e0a0286a86d766bce3edc87e8c9a158.zip | |
update mfm.js (#7435)
* use mfm.js 0.14.0
* use mfm.extract
* use mfm.extract
* use mfm.extract
Diffstat (limited to 'src')
| -rw-r--r-- | src/misc/extract-custom-emojis-from-mfm.ts | 10 | ||||
| -rw-r--r-- | src/misc/extract-hashtags.ts | 11 | ||||
| -rw-r--r-- | src/misc/extract-mentions.ts | 9 | ||||
| -rw-r--r-- | src/misc/extract-url-from-mfm.ts | 13 |
4 files changed, 11 insertions, 32 deletions
diff --git a/src/misc/extract-custom-emojis-from-mfm.ts b/src/misc/extract-custom-emojis-from-mfm.ts index ef2cb1fd6c..b29ce281b3 100644 --- a/src/misc/extract-custom-emojis-from-mfm.ts +++ b/src/misc/extract-custom-emojis-from-mfm.ts @@ -2,13 +2,9 @@ import * as mfm from 'mfm-js'; import { unique } from '@/prelude/array'; export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] { - const emojis = [] as string[]; - - mfm.inspect(nodes, (node) => { - if (node.type === 'emojiCode' && node.props.name.length <= 100) { - emojis.push(node.props.name); - } + const emojiNodes = mfm.extract(nodes, (node) => { + return (node.type === 'emojiCode' && node.props.name.length <= 100); }); - return unique(emojis); + return unique(emojiNodes.map(x => x.props.name)); } diff --git a/src/misc/extract-hashtags.ts b/src/misc/extract-hashtags.ts index f89b699a94..b0a74df219 100644 --- a/src/misc/extract-hashtags.ts +++ b/src/misc/extract-hashtags.ts @@ -2,13 +2,8 @@ import * as mfm from 'mfm-js'; import { unique } from '@/prelude/array'; export function extractHashtags(nodes: mfm.MfmNode[]): string[] { - const hashtags = [] as string[]; + const hashtagNodes = mfm.extract(nodes, (node) => node.type === 'hashtag'); + const hashtags = unique(hashtagNodes.map(x => x.props.hashtag)); - mfm.inspect(nodes, (node) => { - if (node.type === 'hashtag') { - hashtags.push(node.props.hashtag); - } - }); - - return unique(hashtags); + return hashtags; } diff --git a/src/misc/extract-mentions.ts b/src/misc/extract-mentions.ts index a0e2fb6d57..cc19b161a8 100644 --- a/src/misc/extract-mentions.ts +++ b/src/misc/extract-mentions.ts @@ -4,13 +4,8 @@ import * as mfm from 'mfm-js'; export function extractMentions(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] { // TODO: 重複を削除 - const mentions = [] as mfm.MfmMention['props'][]; - - mfm.inspect(nodes, (node) => { - if (node.type === 'mention') { - mentions.push(node.props); - } - }); + const mentionNodes = mfm.extract(nodes, (node) => node.type === 'mention'); + const mentions = mentionNodes.map(x => x.props); return mentions; } diff --git a/src/misc/extract-url-from-mfm.ts b/src/misc/extract-url-from-mfm.ts index ec3b019ea5..e6d5d0104a 100644 --- a/src/misc/extract-url-from-mfm.ts +++ b/src/misc/extract-url-from-mfm.ts @@ -6,17 +6,10 @@ import { unique } from '@/prelude/array'; const removeHash = (x: string) => x.replace(/#[^#]*$/, ''); export function extractUrlFromMfm(nodes: mfm.MfmNode[], respectSilentFlag = true): string[] { - let urls = [] as string[]; - - mfm.inspect(nodes, (node) => { - if (node.type === 'url') { - urls.push(node.props.url); - } else if (node.type === 'link' && (!respectSilentFlag || !node.props.silent)) { - urls.push(node.props.url); - } + const urlNodes = mfm.extract(nodes, (node) => { + return (node.type === 'url') || (node.type === 'link' && (!respectSilentFlag || !node.props.silent)); }); - - urls = unique(urls); + const urls: string[] = unique(urlNodes.map(x => x.props.url)); return urls.reduce((array, url) => { const urlWithoutHash = removeHash(url); |