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

@ -1,10 +1,19 @@
// test is located in test/extract-mentions
import { MentionNode, MfmForest } from '../mfm/prelude';
import { preorderF } from '../prelude/tree';
import * as mfm from 'mfm-js';
export default function(mfmForest: MfmForest): MentionNode['props'][] {
export default function(nodes: mfm.MfmNode[]): mfm.MfmMention['props'][] {
// TODO: 重複を削除
const mentionNodes = preorderF(mfmForest).filter(x => x.type === 'mention') as MentionNode[];
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);
}