update mfm.js (#7435)
* use mfm.js 0.14.0 * use mfm.extract * use mfm.extract * use mfm.extract
This commit is contained in:
parent
bffcfd92da
commit
1ec3338d2e
5 changed files with 12 additions and 33 deletions
|
@ -181,7 +181,7 @@
|
||||||
"markdown-it": "12.0.4",
|
"markdown-it": "12.0.4",
|
||||||
"markdown-it-anchor": "7.1.0",
|
"markdown-it-anchor": "7.1.0",
|
||||||
"matter-js": "0.16.1",
|
"matter-js": "0.16.1",
|
||||||
"mfm-js": "0.12.0",
|
"mfm-js": "0.14.0",
|
||||||
"mocha": "8.3.2",
|
"mocha": "8.3.2",
|
||||||
"moji": "0.5.1",
|
"moji": "0.5.1",
|
||||||
"ms": "2.1.3",
|
"ms": "2.1.3",
|
||||||
|
|
|
@ -2,13 +2,9 @@ import * as mfm from 'mfm-js';
|
||||||
import { unique } from '@/prelude/array';
|
import { unique } from '@/prelude/array';
|
||||||
|
|
||||||
export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
|
export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
|
||||||
const emojis = [] as string[];
|
const emojiNodes = mfm.extract(nodes, (node) => {
|
||||||
|
return (node.type === 'emojiCode' && node.props.name.length <= 100);
|
||||||
mfm.inspect(nodes, (node) => {
|
|
||||||
if (node.type === 'emojiCode' && node.props.name.length <= 100) {
|
|
||||||
emojis.push(node.props.name);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return unique(emojis);
|
return unique(emojiNodes.map(x => x.props.name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,8 @@ import * as mfm from 'mfm-js';
|
||||||
import { unique } from '@/prelude/array';
|
import { unique } from '@/prelude/array';
|
||||||
|
|
||||||
export function extractHashtags(nodes: mfm.MfmNode[]): string[] {
|
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) => {
|
return hashtags;
|
||||||
if (node.type === 'hashtag') {
|
|
||||||
hashtags.push(node.props.hashtag);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return unique(hashtags);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,8 @@ import * as mfm from 'mfm-js';
|
||||||
|
|
||||||
export function extractMentions(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
|
export function extractMentions(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
|
||||||
// TODO: 重複を削除
|
// TODO: 重複を削除
|
||||||
const mentions = [] as mfm.MfmMention['props'][];
|
const mentionNodes = mfm.extract(nodes, (node) => node.type === 'mention');
|
||||||
|
const mentions = mentionNodes.map(x => x.props);
|
||||||
mfm.inspect(nodes, (node) => {
|
|
||||||
if (node.type === 'mention') {
|
|
||||||
mentions.push(node.props);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return mentions;
|
return mentions;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,10 @@ import { unique } from '@/prelude/array';
|
||||||
const removeHash = (x: string) => x.replace(/#[^#]*$/, '');
|
const removeHash = (x: string) => x.replace(/#[^#]*$/, '');
|
||||||
|
|
||||||
export function extractUrlFromMfm(nodes: mfm.MfmNode[], respectSilentFlag = true): string[] {
|
export function extractUrlFromMfm(nodes: mfm.MfmNode[], respectSilentFlag = true): string[] {
|
||||||
let urls = [] as string[];
|
const urlNodes = mfm.extract(nodes, (node) => {
|
||||||
|
return (node.type === 'url') || (node.type === 'link' && (!respectSilentFlag || !node.props.silent));
|
||||||
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 urls: string[] = unique(urlNodes.map(x => x.props.url));
|
||||||
urls = unique(urls);
|
|
||||||
|
|
||||||
return urls.reduce((array, url) => {
|
return urls.reduce((array, url) => {
|
||||||
const urlWithoutHash = removeHash(url);
|
const urlWithoutHash = removeHash(url);
|
||||||
|
|
Loading…
Reference in a new issue