Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
41fecb80
"docs/source/Tutorial/WebUI.rst" did not exist on "f13a9222f1e6b21d1c342b44e1ae17178e550acc"
Commit
41fecb80
authored
Jul 20, 2024
by
Timothy J. Baek
Browse files
enh: latex
parent
52cf06b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+1
-0
src/lib/utils/index.ts
src/lib/utils/index.ts
+20
-0
No files found.
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
41fecb80
...
@@ -182,6 +182,7 @@
...
@@ -182,6 +182,7 @@
{ left: '\\[', right: '\\]', display: false },
{ left: '\\[', right: '\\]', display: false },
{ left: '[ ', right: ' ]', display: false },
{ left: '[ ', right: ' ]', display: false },
{ left: '\\begin{equation}', right: '\\end{equation}', display: true },
{ left: '\\begin{equation}', right: '\\end{equation}', display: true },
{ left: '\\begin{matrix}', right: '\\end{matrix}', display: true },
{ left: '\\begin{align}', right: '\\end{align}', display: true },
{ left: '\\begin{align}', right: '\\end{align}', display: true },
{ left: '\\begin{alignat}', right: '\\end{alignat}', display: true },
{ left: '\\begin{alignat}', right: '\\end{alignat}', display: true },
{ left: '\\begin{gather}', right: '\\end{gather}', display: true },
{ left: '\\begin{gather}', right: '\\end{gather}', display: true },
...
...
src/lib/utils/index.ts
View file @
41fecb80
...
@@ -6,9 +6,29 @@ import { WEBUI_BASE_URL } from '$lib/constants';
...
@@ -6,9 +6,29 @@ import { WEBUI_BASE_URL } from '$lib/constants';
// Helper functions
// Helper functions
//////////////////////////
//////////////////////////
const
convertLatexToSingleLine
=
(
content
)
=>
{
// Patterns to match multiline LaTeX blocks
const
patterns
=
[
/
(\$\$[\s\S]
*
?\$\$)
/g
,
// Match $$ ... $$
/
(\\[\s\S]
*
?\\
]
)
/g
,
// Match \[ ... \]
/
(\$\[\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
+/g
,
'
'
).
trim
();
});
});
return
content
;
};
export
const
sanitizeResponseContent
=
(
content
:
string
)
=>
{
export
const
sanitizeResponseContent
=
(
content
:
string
)
=>
{
// replace single backslash with double backslash
// replace single backslash with double backslash
content
=
content
.
replace
(
/
\\
/g
,
'
\\\\
'
);
content
=
content
.
replace
(
/
\\
/g
,
'
\\\\
'
);
content
=
convertLatexToSingleLine
(
content
);
// First, temporarily replace valid <video> tags with a placeholder
// First, temporarily replace valid <video> tags with a placeholder
const
videoTagRegex
=
/<video
\s
+src="
([^
"
]
+
)
"
\s
+controls><
\/
video>/gi
;
const
videoTagRegex
=
/<video
\s
+src="
([^
"
]
+
)
"
\s
+controls><
\/
video>/gi
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment