1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-11-25 07:36:24 +09:00

update mfm.js (#7435)

* use mfm.js 0.14.0

* use mfm.extract

* use mfm.extract

* use mfm.extract
This commit is contained in:
marihachi 2021-04-11 00:18:29 +09:00 committed by GitHub
parent bffcfd92da
commit 1ec3338d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 33 deletions

View File

@ -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",

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);