From f7602be0e7a3c73b7be357029b876f825b2d3885 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 15 Apr 2023 17:53:17 +0000 Subject: [PATCH] fix: disable "Search" keyword (#9856) Related: #9816 #9830 I was so careless that I didn't know "Search" was also a keyword. I disabled that and fixed a minor bug. Co-authored-by: naskya Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9856 Co-authored-by: naskya Co-committed-by: naskya --- packages/client/src/components/mfm.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index 169fc7cfe8..6f1b4256dd 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -12,7 +12,6 @@ import MkGoogle from "@/components/MkGoogle.vue"; import MkSparkle from "@/components/MkSparkle.vue"; import MkA from "@/components/global/MkA.vue"; import { host } from "@/config"; -import { MFM_TAGS } from "@/scripts/mfm-tags"; import { reducedMotion } from "@/scripts/reduced-motion"; import { defaultStore } from "@/store"; @@ -461,7 +460,7 @@ export default defineComponent({ case "search": { // Disable "search" keyword // (see the issue #9816 on Codeberg) - if (token.props.content.endsWith("search")) { + if (token.props.content.slice(-6).toLowerCase() === "search") { const sentinel = "#"; let ast2 = (isPlain ? mfm.parseSimple : mfm.parse)( token.props.content.slice(0, -6) + sentinel, @@ -473,19 +472,32 @@ export default defineComponent({ ast2[ast2.length - 1].props.text = ast2[ ast2.length - 1 ].props.text.slice(0, -1); + } else { + // I don't think this scope is reachable + console.warn( + "Something went wrong while parsing MFM. Please send a bug report, if possible.", + ); } let prefix = "\n"; if ( index === 0 || - ["blockCode", "mathBlock", "search", "quote"].includes( - ast[index - 1].type, - ) + [ + "blockCode", + "center", + "mathBlock", + "quote", + "search", + ].includes(ast[index - 1].type) ) { prefix = ""; } - return [prefix, ...genEl(ast2), "search\n"]; + return [ + prefix, + ...genEl(ast2), + `${token.props.content.slice(-6)}\n`, + ]; } return [