From 62a0f43c8468efcde83290dbf3f76ffa1510b2c7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 25 Dec 2023 17:31:21 +0000 Subject: [PATCH 1/7] add package --- packages/frontend/package.json | 1 + pnpm-lock.yaml | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 275a6ad025..b46663aca1 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -51,6 +51,7 @@ "insert-text-at-cursor": "0.3.0", "is-file-animated": "1.0.2", "json5": "2.2.3", + "katex": "^0.16.9", "matter-js": "0.19.0", "misskey-js": "workspace:*", "photoswipe": "5.4.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec05ad3485..c4c51bca2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -756,6 +756,9 @@ importers: json5: specifier: 2.2.3 version: 2.2.3 + katex: + specifier: ^0.16.9 + version: 0.16.9 matter-js: specifier: 0.19.0 version: 0.19.0 @@ -14554,6 +14557,13 @@ packages: safe-buffer: 5.2.1 dev: false + /katex@0.16.9: + resolution: {integrity: sha512-fsSYjWS0EEOwvy81j3vRA8TEAhQhKiqO+FQaKWp0m39qwOzHVBgAUBIXWj1pB+O2W3fIpNa6Y9KSKCVbfPhyAQ==} + hasBin: true + dependencies: + commander: 9.5.0 + dev: false + /keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: From 6f63ff62fcfbba5dbb48e4761c5353c97e361a7e Mon Sep 17 00:00:00 2001 From: Marie Date: Mon, 25 Dec 2023 18:40:49 +0100 Subject: [PATCH 2/7] fix: autocomplete on users being janky --- packages/frontend/src/scripts/autocomplete.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/src/scripts/autocomplete.ts b/packages/frontend/src/scripts/autocomplete.ts index 6f3d3ba8e1..2a9a42ace5 100644 --- a/packages/frontend/src/scripts/autocomplete.ts +++ b/packages/frontend/src/scripts/autocomplete.ts @@ -101,7 +101,7 @@ export class Autocomplete { if (isMention && this.onlyType.includes('user')) { const username = text.substring(mentionIndex + 1); - if (username !== '' && username.match(/^[a-zA-Z0-9_.]+$/)) { + if (username !== '' && username.match(/^[a-zA-Z0-9_]+$/)) { this.open('user', username); opened = true; } else if (username === '') { From 8d291ef03982037b391f7529d5a4c7feb1972823 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 25 Dec 2023 18:12:55 +0000 Subject: [PATCH 3/7] 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': { From 8fd72fa12cd7878c40571294cc37be30c9ca9090 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 25 Dec 2023 19:51:41 +0000 Subject: [PATCH 4/7] remove spurious indent --- packages/frontend/src/components/MkFormula.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/components/MkFormula.vue b/packages/frontend/src/components/MkFormula.vue index 64d0cc0b4e..039cef8da8 100644 --- a/packages/frontend/src/components/MkFormula.vue +++ b/packages/frontend/src/components/MkFormula.vue @@ -1,6 +1,6 @@