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,12 +1,12 @@
import { EntityRepository, Repository, In } from 'typeorm';
import * as mfm from 'mfm-js';
import { Note } from '../entities/note';
import { User } from '../entities/user';
import { Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '..';
import { SchemaType } from '@/misc/schema';
import { nyaize } from '@/misc/nyaize';
import { awaitAll } from '../../prelude/await-all';
import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '@/misc/reaction-lib';
import { toString } from '../../mfm/to-string';
import { parse } from '../../mfm/parse';
import { NoteReaction } from '../entities/note-reaction';
import { aggregateNoteEmojis, populateEmojis, prefetchEmojis } from '@/misc/populate-emojis';
@ -223,8 +223,13 @@ export class NoteRepository extends Repository<Note> {
});
if (packed.user.isCat && packed.text) {
const tokens = packed.text ? parse(packed.text) : [];
packed.text = toString(tokens, { doNyaize: true });
const tokens = packed.text ? mfm.parse(packed.text) : [];
mfm.inspect(tokens, node => {
if (node.type === 'text') {
node.props.text = nyaize(node.props.text);
}
});
packed.text = mfm.toString(tokens);
}
if (!opts.skipHide) {