mirror of
https://github.com/open-webui/open-webui
synced 2025-04-24 00:06:11 +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
|
// 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) => {
|
export const replaceTokens = (content, char, user) => {
|
||||||
const charToken = /{{char}}/gi;
|
const charToken = /{{char}}/gi;
|
||||||
const userToken = /{{user}}/gi;
|
const userToken = /{{user}}/gi;
|
||||||
@ -68,7 +51,6 @@ export const sanitizeResponseContent = (content: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const processResponseContent = (content: string) => {
|
export const processResponseContent = (content: string) => {
|
||||||
content = convertLatexToSingleLine(content);
|
|
||||||
return content.trim();
|
return content.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ function generateRegexRules(delimiters) {
|
|||||||
|
|
||||||
if (!display) {
|
if (!display) {
|
||||||
inlinePatterns.push(
|
inlinePatterns.push(
|
||||||
`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`
|
`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
blockPatterns.push(
|
blockPatterns.push(
|
||||||
`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`
|
`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -109,6 +109,8 @@ function katexTokenizer(src, tokens, displayMode: boolean) {
|
|||||||
|
|
||||||
const match = src.match(ruleReg);
|
const match = src.match(ruleReg);
|
||||||
|
|
||||||
|
console.log("searching:", src);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const text = match
|
const text = match
|
||||||
.slice(2)
|
.slice(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user