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
31 changed files with 262 additions and 1771 deletions

View File

@@ -9,8 +9,8 @@
import { TextBlock } from '@client/scripts/hpml/block';
import { Hpml } from '@client/scripts/hpml/evaluator';
import { defineAsyncComponent, defineComponent, PropType } from 'vue';
import { parse } from '../../../mfm/parse';
import { unique } from '../../../prelude/array';
import * as mfm from 'mfm-js';
import { extractUrlFromMfm } from '@/misc/extract-url-from-mfm';
export default defineComponent({
components: {
@@ -34,11 +34,7 @@ export default defineComponent({
computed: {
urls(): string[] {
if (this.text) {
const ast = parse(this.text);
// TODO: 再帰的にURL要素がないか調べる
return unique(ast
.filter(t => ((t.node.type == 'url' || t.node.type == 'link') && t.node.props.url && !t.node.props.silent))
.map(t => t.node.props.url));
return extractUrlFromMfm(mfm.parse(this.text));
} else {
return [];
}