Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
math_tutor_dev
public_math_tutor
Commits
1286052a
Commit
1286052a
authored
Mar 06, 2026
by
Kantz
Browse files
Formel anzeige mit zwei malpunkten
parent
c0d93773
Changes
3
Hide whitespace changes
Inline
Side-by-side
math-tutor/frontend/src/components/Chat/MessageBubble.tsx
View file @
1286052a
import
{
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useMemo
,
useRef
,
useState
}
from
"
react
"
;
import
ReactMarkdown
,
{
defaultUrlTransform
}
from
"
react-markdown
"
;
import
ReactMarkdown
,
{
defaultUrlTransform
}
from
"
react-markdown
"
;
import
type
{
RetrievedDoc
}
from
"
../Retrieval/DocPanel
"
;
import
type
{
RetrievedDoc
}
from
"
../Retrieval/DocPanel
"
;
import
{
t
}
from
"
../../i18n
"
;
import
{
t
}
from
"
../../i18n
"
;
import
{
escapeAsterisksInsideMath
}
from
"
../../utils/mathMarkdown
"
;
type
MessageBubbleProps
=
{
type
MessageBubbleProps
=
{
role
:
"
user
"
|
"
assistant
"
;
role
:
"
user
"
|
"
assistant
"
;
...
@@ -28,6 +29,7 @@ export default function MessageBubble({
...
@@ -28,6 +29,7 @@ export default function MessageBubble({
}:
MessageBubbleProps
)
{
}:
MessageBubbleProps
)
{
const
bubbleRef
=
useRef
<
HTMLDivElement
|
null
>
(
null
);
const
bubbleRef
=
useRef
<
HTMLDivElement
|
null
>
(
null
);
const
[
isRawView
,
setIsRawView
]
=
useState
(
false
);
const
[
isRawView
,
setIsRawView
]
=
useState
(
false
);
const
renderedText
=
useMemo
(()
=>
escapeAsterisksInsideMath
(
text
),
[
text
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
isRawView
)
{
if
(
isRawView
)
{
...
@@ -146,7 +148,7 @@ export default function MessageBubble({
...
@@ -146,7 +148,7 @@ export default function MessageBubble({
},
},
}
}
}
}
>
>
{
t
ext
}
{
renderedT
ext
}
</
ReactMarkdown
>
</
ReactMarkdown
>
)
}
)
}
</
div
>
</
div
>
...
...
math-tutor/frontend/src/components/Retrieval/DocCard.tsx
View file @
1286052a
import
{
useEffect
,
useRef
}
from
"
react
"
;
import
{
useEffect
,
useMemo
,
useRef
}
from
"
react
"
;
import
ReactMarkdown
from
"
react-markdown
"
;
import
ReactMarkdown
from
"
react-markdown
"
;
import
{
t
}
from
"
../../i18n
"
;
import
{
t
}
from
"
../../i18n
"
;
import
{
escapeAsterisksInsideMath
}
from
"
../../utils/mathMarkdown
"
;
declare
global
{
declare
global
{
interface
Window
{
interface
Window
{
...
@@ -30,6 +31,10 @@ export default function DocCard({
...
@@ -30,6 +31,10 @@ export default function DocCard({
defaultOpen
=
false
,
defaultOpen
=
false
,
}:
DocCardProps
)
{
}:
DocCardProps
)
{
const
contentRef
=
useRef
<
HTMLDivElement
|
null
>
(
null
);
const
contentRef
=
useRef
<
HTMLDivElement
|
null
>
(
null
);
const
renderedSnippet
=
useMemo
(
()
=>
escapeAsterisksInsideMath
(
snippetMarkdown
),
[
snippetMarkdown
]
);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
typeset
=
()
=>
{
const
typeset
=
()
=>
{
...
@@ -60,7 +65,7 @@ export default function DocCard({
...
@@ -60,7 +65,7 @@ export default function DocCard({
</
summary
>
</
summary
>
{
subtitle
?
<
div
className
=
"doc-subtitle"
>
{
subtitle
}
</
div
>
:
null
}
{
subtitle
?
<
div
className
=
"doc-subtitle"
>
{
subtitle
}
</
div
>
:
null
}
<
div
className
=
"doc-snippet"
ref
=
{
contentRef
}
>
<
div
className
=
"doc-snippet"
ref
=
{
contentRef
}
>
<
ReactMarkdown
>
{
snippetMarkdown
}
</
ReactMarkdown
>
<
ReactMarkdown
>
{
renderedSnippet
}
</
ReactMarkdown
>
</
div
>
</
div
>
<
div
className
=
"doc-actions"
>
<
div
className
=
"doc-actions"
>
<
button
className
=
"btn small"
type
=
"button"
onClick
=
{
onInspect
}
>
<
button
className
=
"btn small"
type
=
"button"
onClick
=
{
onInspect
}
>
...
...
math-tutor/frontend/src/utils/mathMarkdown.ts
0 → 100644
View file @
1286052a
const
MATH_SEGMENT_PATTERN
=
/
(\$\$[\s\S]
*
?\$\$
|
\\\[[\s\S]
*
?\\\]
|
\\\([\s\S]
*
?\\\)
|
\$(?:\\
.|
[^
$
\\\n])
+
\$)
/g
;
const
escapeAsterisks
=
(
value
:
string
)
=>
value
.
replace
(
/
\*
/g
,
"
\\
*
"
);
export
const
escapeAsterisksInsideMath
=
(
input
:
string
):
string
=>
{
return
input
.
replace
(
MATH_SEGMENT_PATTERN
,
(
segment
)
=>
{
if
(
segment
.
startsWith
(
"
$$
"
)
&&
segment
.
endsWith
(
"
$$
"
))
{
const
inner
=
segment
.
slice
(
2
,
-
2
);
return
`$$
${
escapeAsterisks
(
inner
)}
$$`
;
}
if
(
segment
.
startsWith
(
"
\\
[
"
)
&&
segment
.
endsWith
(
"
\\
]
"
))
{
const
inner
=
segment
.
slice
(
2
,
-
2
);
return
`\\[
${
escapeAsterisks
(
inner
)}
\\]`
;
}
if
(
segment
.
startsWith
(
"
\\
(
"
)
&&
segment
.
endsWith
(
"
\\
)
"
))
{
const
inner
=
segment
.
slice
(
2
,
-
2
);
return
`\\(
${
escapeAsterisks
(
inner
)}
\\)`
;
}
if
(
segment
.
startsWith
(
"
$
"
)
&&
segment
.
endsWith
(
"
$
"
))
{
const
inner
=
segment
.
slice
(
1
,
-
1
);
return
`$
${
escapeAsterisks
(
inner
)}
$`
;
}
return
segment
;
});
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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