mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 05:24:02 +00:00
fix: Simplify regex
This commit is contained in:
parent
377cc427b6
commit
0bfbace9aa
@ -8,23 +8,6 @@ import { TTS_RESPONSE_SPLIT } from '$lib/types';
|
||||
// Helper functions
|
||||
//////////////////////////
|
||||
|
||||
const convertLatexToSingleLine = (content) => {
|
||||
// Patterns to match multiline LaTeX blocks
|
||||
const patterns = [
|
||||
/(\$\$\s[\s\S]*?\s\$\$)/g, // Match $$ ... $$
|
||||
/(\\\[[\s\S]*?\\\])/g, // Match \[ ... \]
|
||||
/(\\begin\{[a-z]+\}[\s\S]*?\\end\{[a-z]+\})/g // Match \begin{...} ... \end{...}
|
||||
];
|
||||
|
||||
patterns.forEach((pattern) => {
|
||||
content = content.replace(pattern, (match) => {
|
||||
return match.replace(/\s*\n\s*/g, ' ').trim();
|
||||
});
|
||||
});
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
export const replaceTokens = (content, char, user) => {
|
||||
const charToken = /{{char}}/gi;
|
||||
const userToken = /{{user}}/gi;
|
||||
@ -68,7 +51,6 @@ export const sanitizeResponseContent = (content: string) => {
|
||||
};
|
||||
|
||||
export const processResponseContent = (content: string) => {
|
||||
content = convertLatexToSingleLine(content);
|
||||
return content.trim();
|
||||
};
|
||||
|
||||
|
@ -35,11 +35,11 @@ function generateRegexRules(delimiters) {
|
||||
|
||||
if (!display) {
|
||||
inlinePatterns.push(
|
||||
`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`
|
||||
`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`
|
||||
);
|
||||
} else {
|
||||
blockPatterns.push(
|
||||
`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`
|
||||
`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -109,6 +109,8 @@ function katexTokenizer(src, tokens, displayMode: boolean) {
|
||||
|
||||
const match = src.match(ruleReg);
|
||||
|
||||
console.log("searching:", src);
|
||||
|
||||
if (match) {
|
||||
const text = match
|
||||
.slice(2)
|
||||
|
Loading…
Reference in New Issue
Block a user