Use mfm-js for MFM parsing (#7415)

* wip

* Update mfm.ts

* wip

* update mfmjs

* refactor

* nanka

* Update mfm.ts

* Update to-html.ts

* Update to-html.ts

* wip

* fix test

* fix test
This commit is contained in:
syuilo 2021-04-02 10:36:11 +09:00 committed by GitHub
parent b378066ebf
commit 1f4ae2f63a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 262 additions and 1771 deletions

View file

@ -0,0 +1,18 @@
import * as mfm from 'mfm-js';
import { unique } from '@/prelude/array';
export function extractCustomEmojisFromMfm(nodes: mfm.MfmNode[]): string[] {
const emojiNodes = [] as mfm.MfmEmojiCode[];
function scan(nodes: mfm.MfmNode[]) {
for (const node of nodes) {
if (node.type === 'emojiCode') emojiNodes.push(node);
else if (node.children) scan(node.children);
}
}
scan(nodes);
const emojis = emojiNodes.filter(x => x.props.name.length <= 100).map(x => x.props.name!);
return unique(emojis);
}