refactor mfm extract (#7434)
* refactor extractCustomEmojisFromMfm() * refactor extract-hashtags * refactor extract-mentions * refactor extract-hashtags * refactor extract-url-from-mfm * refactor extract-mentions
This commit is contained in:
parent
56a28923ca
commit
3a6331693a
9 changed files with 34 additions and 53 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue