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,17 +2,13 @@ import * as mfm from 'mfm-js';
|
|||
import { unique } from '@/prelude/array';
|
||||
|
||||
export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
|
||||
const emojiNodes = [] as mfm.MfmEmojiCode[];
|
||||
const emojis = [] as string[];
|
||||
|
||||
function scan(nodes: mfm.MfmNode[]) {
|
||||
for (const node of nodes) {
|
||||
if (node.type === 'emojiCode') emojiNodes.push(node);
|
||||
else if (node.children) scan(node.children);
|
||||
mfm.inspect(nodes, (node) => {
|
||||
if (node.type === 'emojiCode' && node.props.name.length <= 100) {
|
||||
emojis.push(node.props.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
scan(nodes);
|
||||
|
||||
const emojis = emojiNodes.filter(x => x.props.name.length <= 100).map(x => x.props.name!);
|
||||
return unique(emojis);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue