summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarihachi <marihachi0620@gmail.com>2021-04-11 00:18:29 +0900
committerGitHub <noreply@github.com>2021-04-11 00:18:29 +0900
commit1ec3338d2e0a0286a86d766bce3edc87e8c9a158 (patch)
treefaa0aa3be4e959eb215a2e6e800cb96b137b55da
parentTweak UI (diff)
downloadmisskey-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
-rw-r--r--package.json2
-rw-r--r--src/misc/extract-custom-emojis-from-mfm.ts10
-rw-r--r--src/misc/extract-hashtags.ts11
-rw-r--r--src/misc/extract-mentions.ts9
-rw-r--r--src/misc/extract-url-from-mfm.ts13
5 files changed, 12 insertions, 33 deletions
diff --git a/package.json b/package.json
index 954a8cc628..aaa3a43764 100644
--- a/package.json
+++ b/package.json
@@ -181,7 +181,7 @@
"markdown-it": "12.0.4",
"markdown-it-anchor": "7.1.0",
"matter-js": "0.16.1",
- "mfm-js": "0.12.0",
+ "mfm-js": "0.14.0",
"mocha": "8.3.2",
"moji": "0.5.1",
"ms": "2.1.3",
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);