cherry-pick 8f4bfbf1
This commit is contained in:
parent
fe49220b23
commit
338328ae81
2 changed files with 9 additions and 2 deletions
|
|
@ -76,15 +76,21 @@ export const ChatMessage = ({
|
||||||
? message.content
|
? message.content
|
||||||
: (displayContent !== undefined ? displayContent : (message.content || ''))
|
: (displayContent !== undefined ? displayContent : (message.content || ''))
|
||||||
|
|
||||||
// Load KaTeX rehype plugin dynamically
|
// Load KaTeX dynamically with extensions
|
||||||
// Note: KaTeX extensions (mhchem, copy-tex) are imported statically in main.tsx
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadKaTeX = async () => {
|
const loadKaTeX = async () => {
|
||||||
try {
|
try {
|
||||||
|
// Load KaTeX extensions (must be loaded before rehype-katex)
|
||||||
|
// 1. mhchem: enables \ce and \pu commands for chemistry formulas
|
||||||
|
await import('katex/contrib/mhchem');
|
||||||
|
// 2. copy-tex: allows users to copy rendered formulas as LaTeX source code
|
||||||
|
await import('katex/contrib/copy-tex');
|
||||||
|
// Then load rehype-katex
|
||||||
const { default: rehypeKatex } = await import('rehype-katex');
|
const { default: rehypeKatex } = await import('rehype-katex');
|
||||||
setKatexPlugin(() => rehypeKatex);
|
setKatexPlugin(() => rehypeKatex);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load KaTeX plugin:', error);
|
console.error('Failed to load KaTeX plugin:', error);
|
||||||
|
// Set to null to ensure we don't try to use a failed plugin
|
||||||
setKatexPlugin(null);
|
setKatexPlugin(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
1
lightrag_webui/src/types/katex.d.ts
vendored
1
lightrag_webui/src/types/katex.d.ts
vendored
|
|
@ -1 +1,2 @@
|
||||||
declare module 'katex/contrib/mhchem';
|
declare module 'katex/contrib/mhchem';
|
||||||
|
declare module 'katex/contrib/copy-tex';
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue