Sharkey/src/misc/extract-mentions.ts

20 lines
464 B
TypeScript
Raw Normal View History

// test is located in test/extract-mentions
2018-12-19 03:16:29 +01:00
import * as mfm from 'mfm-js';
2018-12-19 03:16:29 +01:00
export default function(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
// TODO: 重複を削除
const mentionNodes = [] as mfm.MfmMention[];
function scan(nodes: mfm.MfmNode[]) {
for (const node of nodes) {
if (node.type === 'mention') mentionNodes.push(node);
else if (node.children) scan(node.children);
}
}
scan(nodes);
return mentionNodes.map(x => x.props);
2018-12-19 03:16:29 +01:00
}