From 7dd71d9d82941d34cfcdbcb6f3a21c74bee2c93d Mon Sep 17 00:00:00 2001 From: Morgan Date: Thu, 25 Apr 2024 09:10:52 +0900 Subject: [PATCH] fix linter thing.. --- src/lib/Code.svelte | 16 +++---- src/lib/Codespan.svelte | 10 ++--- src/lib/EditMessage.svelte | 86 +++++++++++++++++++------------------- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/lib/Code.svelte b/src/lib/Code.svelte index 03572a2a..80009813 100644 --- a/src/lib/Code.svelte +++ b/src/lib/Code.svelte @@ -27,8 +27,8 @@ type LanguageType } from 'svelte-highlight/languages/index' - import katex from 'katex'; - import 'katex/contrib/mhchem'; + import katex from 'katex' + import 'katex/contrib/mhchem' export const type: 'code' = 'code' export const raw: string = '' @@ -36,18 +36,18 @@ export let lang: string | undefined export let text: string - let renderedMath: string | undefined; + let renderedMath: string | undefined - $: if (lang === "rendermath") { + $: if (lang === 'rendermath') { renderedMath = katex.renderToString(text, { throwOnError: false, displayMode: true - }); + }) } else { - renderedMath = undefined; + renderedMath = undefined } - // Map lang string to LanguageType + // Map lang string to LanguageType let language: LanguageType // If no language is set, try to detect it using flourite @@ -131,7 +131,7 @@ {@html style} -{#if lang === "rendermath"} +{#if lang === 'rendermath'} {@html renderedMath} {:else}
diff --git a/src/lib/Codespan.svelte b/src/lib/Codespan.svelte index 75c81cfc..2ccf5cd1 100644 --- a/src/lib/Codespan.svelte +++ b/src/lib/Codespan.svelte @@ -1,14 +1,14 @@ diff --git a/src/lib/EditMessage.svelte b/src/lib/EditMessage.svelte index 36699474..90d4dd58 100644 --- a/src/lib/EditMessage.svelte +++ b/src/lib/EditMessage.svelte @@ -14,12 +14,12 @@ import { getImage } from './ImageStore.svelte' import { getModelDetail } from './Models.svelte' - import '../katex.min.css'; + import '../katex.min.css' export let message:Message export let chatId:number export let chat:Chat - + const renderLatexFlag = import.meta.env.VITE_RENDER_LATEX || true $: chatSettings = chat.settings @@ -37,10 +37,10 @@ mangle: false // Do not mangle email addresses } - const renderers = { - code: Code, + const renderers = { + code: Code, html: Code, - codespan: Codespan, + codespan: Codespan } const getDisplayMessage = ():string => { @@ -225,55 +225,55 @@ document.body.removeChild(a) } - const preprocessMath = (text: string): string => { + const preprocessMath = (text: string): string => { if (renderLatexFlag !== true) { - return text + return text } - var codeBlockPlaceholderPrefix = "__prefix__c0d3b10ck__"; + let codeBlockPlaceholderPrefix = '__prefix__c0d3b10ck__' while (text.indexOf(codeBlockPlaceholderPrefix) > 0) { - codeBlockPlaceholderPrefix = codeBlockPlaceholderPrefix + "_"; + codeBlockPlaceholderPrefix = codeBlockPlaceholderPrefix + '_' } - let index = 0; - const codeBlocks = []; + let index = 0 + const codeBlocks = [] - const codeBlockRegex = /(```[\s\S]*?```|`[^`]*`)/g; - + const codeBlockRegex = /(```[\s\S]*?```|`[^`]*`)/g + text = text.replace(codeBlockRegex, (match) => { - const placeholder = `${codeBlockPlaceholderPrefix}idx${index}__`; - codeBlocks.push(match); - index++; - return placeholder; - }); + const placeholder = `${codeBlockPlaceholderPrefix}idx${index}__` + codeBlocks.push(match) + index++ + return placeholder + }) text = text - .replace(/(\\\[((?:\s|\S)*?)\\\])|(\$\$((?:\s|\S)*?)\$\$)/g, (match, p1, p2, p3, p4) => { - let math = p2 || p4; - return '\n```rendermath\n' + math.trim() + '\n```\n'; - }) - .replace(/(\\\((?!\$)(.*?)\\\))|(? { - let math = p2 || p3; - return '`rendermath' + math.trim() + '`'; - }); - - // .replace(/\\\[((?:\s|\S)*?)\\\]/g, (match, math) => { - // return '\n```rendermath\n' + math.trim() + '\n```\n' - // }) - // .replace(/\$\$((?:\s|\S)*?)\$\$/g, (match, math) => { - // return '\n```rendermath\n' + math.trim() + '\n```\n' - // }) - // .replace(/\\\((?!\$)(.*?[^\\])\\\)/g, (match, math) => { - // return '`rendermath' + math.trim() + '`' - // }) - // .replace(/(? { - // return '`rendermath' + math.trim() + '`' - // }) + .replace(/(\\\[((?:\s|\S)*?)\\\])|(\$\$((?:\s|\S)*?)\$\$)/g, (match, p1, p2, p3, p4) => { + const math = p2 || p4 + return '\n```rendermath\n' + math.trim() + '\n```\n' + }) + .replace(/(\\\((?!\$)(.*?)\\\))|(? { + const math = p2 || p3 + return '`rendermath' + math.trim() + '`' + }) + + // .replace(/\\\[((?:\s|\S)*?)\\\]/g, (match, math) => { + // return '\n```rendermath\n' + math.trim() + '\n```\n' + // }) + // .replace(/\$\$((?:\s|\S)*?)\$\$/g, (match, math) => { + // return '\n```rendermath\n' + math.trim() + '\n```\n' + // }) + // .replace(/\\\((?!\$)(.*?[^\\])\\\)/g, (match, math) => { + // return '`rendermath' + math.trim() + '`' + // }) + // .replace(/(? { + // return '`rendermath' + math.trim() + '`' + // }) text = text.replace(new RegExp(`${codeBlockPlaceholderPrefix}idx(\\d+)__`, 'g'), (match, p1) => { - return codeBlocks[p1]; - }); + return codeBlocks[p1] + }) - return text; - }; + return text + }