This commit is contained in:
syuilo 2018-12-19 11:16:29 +09:00
parent 556677be7a
commit 00f979f0e6
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
5 changed files with 34 additions and 16 deletions

View file

@ -0,0 +1,19 @@
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;
}