From 8d291ef03982037b391f7529d5a4c7feb1972823 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 25 Dec 2023 18:12:55 +0000 Subject: [PATCH] formula component based on katex thanks a lot to MoshiBar for the initial implementation! --- .../frontend/src/components/MkFormula.vue | 33 +++++++++++++++++++ .../global/MkMisskeyFlavoredMarkdown.ts | 14 ++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 packages/frontend/src/components/MkFormula.vue diff --git a/packages/frontend/src/components/MkFormula.vue b/packages/frontend/src/components/MkFormula.vue new file mode 100644 index 0000000000..64d0cc0b4e --- /dev/null +++ b/packages/frontend/src/components/MkFormula.vue @@ -0,0 +1,33 @@ + + + + + + + diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 60d12fdcde..83b7ef2e78 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { VNode, h } from 'vue'; +import { VNode, h, defineAsyncComponent } from 'vue'; import * as mfm from '@sharkey/sfm-js'; import * as Misskey from 'misskey-js'; import MkUrl from '@/components/global/MkUrl.vue'; @@ -61,6 +61,8 @@ export default function(props: MfmProps) { const useAnim = defaultStore.state.advancedMfm && defaultStore.state.animatedMfm ? true : props.isAnim ? true : false; + const MkFormula = defineAsyncComponent(() => import('@/components/MkFormula.vue')); + /** * Gen Vue Elements from MFM AST * @param ast MFM AST @@ -410,11 +412,17 @@ export default function(props: MfmProps) { } case 'mathInline': { - return [h('code', token.props.formula)]; + return [h(MkFormula, { + formula: token.props.formula, + block: false, + })]; } case 'mathBlock': { - return [h('code', token.props.formula)]; + return [h(MkFormula, { + formula: token.props.formula, + block: true, + })]; } case 'search': {