Skip to content

Commit

Permalink
fix linter thing..
Browse files Browse the repository at this point in the history
  • Loading branch information
morgan9e committed Apr 25, 2024
1 parent c4e01d0 commit 7dd71d9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
16 changes: 8 additions & 8 deletions src/lib/Code.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
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 = ''
export const codeBlockStyle: 'indented' | undefined = undefined
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<string>
// If no language is set, try to detect it using flourite
Expand Down Expand Up @@ -131,7 +131,7 @@
{@html style}
</svelte:head>

{#if lang === "rendermath"}
{#if lang === 'rendermath'}
{@html renderedMath}
{:else}
<div class="code-block is-relative">
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Codespan.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script lang="ts">
export let raw
import katex from 'katex';
import 'katex/contrib/mhchem';
import katex from 'katex'
import 'katex/contrib/mhchem'
let renderedMath: string | undefined;
if (raw.startsWith("`rendermath")) {
let renderedMath: string | undefined
if (raw.startsWith('`rendermath')) {
renderedMath = katex.renderToString(raw.replace(/`rendermath|`/g, ''), {
throwOnError: false,
displayMode: false
});
})
}
</script>
Expand Down
86 changes: 43 additions & 43 deletions src/lib/EditMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 => {
Expand Down Expand Up @@ -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(/(\\\((?!\$)(.*?)\\\))|(?<!\\|\$)\$(?!\$)(.*?[^\\])\$(?!\$)/g, (match, p1, p2, p3) => {
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(/(?<!\\|\$)\$(?!\$)(.*?[^\\])\$(?!\$)/g, (match, math) => {
// 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(/(\\\((?!\$)(.*?)\\\))|(?<!\\|\$)\$(?!\$)(.*?[^\\])\$(?!\$)/g, (match, p1, p2, p3) => {
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(/(?<!\\|\$)\$(?!\$)(.*?[^\\])\$(?!\$)/g, (match, math) => {
// 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
}
</script>

Expand Down

0 comments on commit 7dd71d9

Please sign in to comment.