From 481db8aba42c098d06af8382b1ff7eefa6d4ba48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sat, 28 Oct 2023 12:41:17 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20MFM=E3=83=91=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E6=99=82=E3=81=AB=E6=84=8F=E5=9B=B3=E3=81=9B=E3=81=9Anyaize?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(#12161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update MkMisskeyFlavoredMarkdown.ts * Update MkMisskeyFlavoredMarkdown.ts * Update MkMisskeyFlavoredMarkdown.ts * Update MkNote.vue * (fix) にゃいずをノートでのみ適用 * fix * Fix lint --- packages/frontend/src/components/MkNote.vue | 8 +++--- .../src/components/MkNoteDetailed.vue | 6 ++--- .../frontend/src/components/MkNotePreview.vue | 2 +- .../frontend/src/components/MkNoteSimple.vue | 2 +- .../frontend/src/components/MkNoteSub.vue | 2 +- .../global/MkMisskeyFlavoredMarkdown.ts | 25 ++++++++++++------- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 339d2ac71..86690eb66 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -43,7 +43,7 @@ SPDX-License-Identifier: AGPL-3.0-only
- +
@@ -53,19 +53,19 @@ SPDX-License-Identifier: AGPL-3.0-only

- +

({{ i18n.ts.private }}) - +
{{ i18n.t('translatedFrom', { x: translation.sourceLang }) }}: - +
diff --git a/packages/frontend/src/components/MkNoteDetailed.vue b/packages/frontend/src/components/MkNoteDetailed.vue index 4f40feffd..cb226984b 100644 --- a/packages/frontend/src/components/MkNoteDetailed.vue +++ b/packages/frontend/src/components/MkNoteDetailed.vue @@ -67,19 +67,19 @@ SPDX-License-Identifier: AGPL-3.0-only

- +

({{ i18n.ts.private }}) - + RN:
{{ i18n.t('translatedFrom', { x: translation.sourceLang }) }}: - +
diff --git a/packages/frontend/src/components/MkNotePreview.vue b/packages/frontend/src/components/MkNotePreview.vue index 923c240cf..79ce60baf 100644 --- a/packages/frontend/src/components/MkNotePreview.vue +++ b/packages/frontend/src/components/MkNotePreview.vue @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
- +
diff --git a/packages/frontend/src/components/MkNoteSimple.vue b/packages/frontend/src/components/MkNoteSimple.vue index f8ef3f3fa..dc401a7ec 100644 --- a/packages/frontend/src/components/MkNoteSimple.vue +++ b/packages/frontend/src/components/MkNoteSimple.vue @@ -10,7 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only

- +

diff --git a/packages/frontend/src/components/MkNoteSub.vue b/packages/frontend/src/components/MkNoteSub.vue index bc52101f4..3cc876700 100644 --- a/packages/frontend/src/components/MkNoteSub.vue +++ b/packages/frontend/src/components/MkNoteSub.vue @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only

- +

diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index f937b5f9e..102aa0db3 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -17,7 +17,7 @@ import MkSparkle from '@/components/MkSparkle.vue'; import MkA from '@/components/global/MkA.vue'; import { host } from '@/config.js'; import { defaultStore } from '@/store.js'; -import { nyaize } from '@/scripts/nyaize.js'; +import { nyaize as doNyaize } from '@/scripts/nyaize.js'; const QUOTE_STYLE = ` display: block; @@ -28,21 +28,27 @@ border-left: solid 3px var(--fg); opacity: 0.7; `.split('\n').join(' '); -export default function(props: { +type MfmProps = { text: string; plain?: boolean; nowrap?: boolean; author?: Misskey.entities.UserLite; - i?: Misskey.entities.UserLite; + i?: Misskey.entities.UserLite | null; isNote?: boolean; emojiUrls?: string[]; rootScale?: number; -}) { - const isNote = props.isNote !== undefined ? props.isNote : true; + nyaize: boolean | 'account'; +}; +// eslint-disable-next-line import/no-default-export +export default function(props: MfmProps) { + const isNote = props.isNote ?? true; + const shouldNyaize = props.nyaize ? props.nyaize === 'account' ? props.author?.isCat : false : false; + + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (props.text == null || props.text === '') return; - const ast = (props.plain ? mfm.parseSimple : mfm.parse)(props.text); + const rootAst = (props.plain ? mfm.parseSimple : mfm.parse)(props.text); const validTime = (t: string | null | undefined) => { if (t == null) return null; @@ -55,13 +61,14 @@ export default function(props: { * Gen Vue Elements from MFM AST * @param ast MFM AST * @param scale How times large the text is + * @param disableNyaize Whether nyaize is disabled or not */ const genEl = (ast: mfm.MfmNode[], scale: number, disableNyaize = false) => ast.map((token): VNode | string | (VNode | string)[] => { switch (token.type) { case 'text': { let text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n'); - if (!disableNyaize && props.author?.isCat) { - text = nyaize(text); + if (!disableNyaize && shouldNyaize) { + text = doNyaize(text); } if (!props.plain) { @@ -377,5 +384,5 @@ export default function(props: { return h('span', { // https://codeday.me/jp/qa/20190424/690106.html style: props.nowrap ? 'white-space: pre; word-wrap: normal; overflow: hidden; text-overflow: ellipsis;' : 'white-space: pre-wrap;', - }, genEl(ast, props.rootScale ?? 1)); + }, genEl(rootAst, props.rootScale ?? 1)); }