1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-24 03:28:43 +09:00
misskey/src/misc/extract-mentions.ts

20 lines
476 B
TypeScript
Raw Normal View History

2018-12-19 11:16:29 +09:00
import parse from '../mfm/parse';
import { Node, IMentionNode } from '../mfm/parser';
export default function(tokens: ReturnType<typeof parse>): IMentionNode['props'][] {
const mentions: IMentionNode['props'][] = [];
const extract = (tokens: Node[]) => {
for (const x of tokens.filter(x => x.name === 'mention')) {
mentions.push(x.props);
}
for (const x of tokens.filter(x => x.children)) {
extract(x.children);
}
};
extract(tokens);
return mentions;
}