summaryrefslogtreecommitdiff
path: root/src/misc/extract-mentions.ts
diff options
context:
space:
mode:
authormarihachi <marihachi0620@gmail.com>2021-04-10 17:50:18 +0900
committerGitHub <noreply@github.com>2021-04-10 17:50:18 +0900
commit3a6331693a2c165fa6bb1a377ad7bf471f2b5550 (patch)
tree64f5f0ca0b3d5edd894a310030ff21126104517a /src/misc/extract-mentions.ts
parentTweak UI (diff)
downloadmisskey-3a6331693a2c165fa6bb1a377ad7bf471f2b5550.tar.gz
misskey-3a6331693a2c165fa6bb1a377ad7bf471f2b5550.tar.bz2
misskey-3a6331693a2c165fa6bb1a377ad7bf471f2b5550.zip
refactor mfm extract (#7434)
* refactor extractCustomEmojisFromMfm() * refactor extract-hashtags * refactor extract-mentions * refactor extract-hashtags * refactor extract-url-from-mfm * refactor extract-mentions
Diffstat (limited to 'src/misc/extract-mentions.ts')
-rw-r--r--src/misc/extract-mentions.ts17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/misc/extract-mentions.ts b/src/misc/extract-mentions.ts
index a9d4b378f3..a0e2fb6d57 100644
--- a/src/misc/extract-mentions.ts
+++ b/src/misc/extract-mentions.ts
@@ -2,18 +2,15 @@
import * as mfm from 'mfm-js';
-export default function(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
+export function extractMentions(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
// TODO: 重複を削除
- const mentionNodes = [] as mfm.MfmMention[];
+ const mentions = [] as mfm.MfmMention['props'][];
- function scan(nodes: mfm.MfmNode[]) {
- for (const node of nodes) {
- if (node.type === 'mention') mentionNodes.push(node);
- else if (node.children) scan(node.children);
+ mfm.inspect(nodes, (node) => {
+ if (node.type === 'mention') {
+ mentions.push(node.props);
}
- }
+ });
- scan(nodes);
-
- return mentionNodes.map(x => x.props);
+ return mentions;
}