cherry-pick 3f6423df
This commit is contained in:
parent
4501740849
commit
fe49220b23
3 changed files with 9 additions and 7 deletions
|
|
@ -76,19 +76,15 @@ export const ChatMessage = ({
|
||||||
? message.content
|
? message.content
|
||||||
: (displayContent !== undefined ? displayContent : (message.content || ''))
|
: (displayContent !== undefined ? displayContent : (message.content || ''))
|
||||||
|
|
||||||
// Load KaTeX dynamically with mhchem extension for chemistry formulas
|
// Load KaTeX rehype plugin dynamically
|
||||||
|
// Note: KaTeX extensions (mhchem, copy-tex) are imported statically in main.tsx
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadKaTeX = async () => {
|
const loadKaTeX = async () => {
|
||||||
try {
|
try {
|
||||||
// First load mhchem extension (must be loaded before rehype-katex)
|
|
||||||
// This enables \ce and \pu commands for chemistry formulas
|
|
||||||
await import('katex/contrib/mhchem');
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ import './index.css'
|
||||||
import AppRouter from './AppRouter'
|
import AppRouter from './AppRouter'
|
||||||
import './i18n.ts';
|
import './i18n.ts';
|
||||||
import 'katex/dist/katex.min.css';
|
import 'katex/dist/katex.min.css';
|
||||||
|
// Import KaTeX extensions at app startup to ensure they are registered before any rendering
|
||||||
|
import 'katex/contrib/mhchem'; // Chemistry formulas: \ce{} and \pu{}
|
||||||
|
import 'katex/contrib/copy-tex'; // Allow copying rendered formulas as LaTeX source
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ export default defineConfig({
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src')
|
'@': path.resolve(__dirname, './src')
|
||||||
}
|
},
|
||||||
|
// Force all modules to use the same katex instance
|
||||||
|
// This ensures mhchem extension registered in main.tsx is available to rehype-katex
|
||||||
|
dedupe: ['katex']
|
||||||
},
|
},
|
||||||
// base: import.meta.env.VITE_BASE_URL || '/webui/',
|
// base: import.meta.env.VITE_BASE_URL || '/webui/',
|
||||||
base: webuiPrefix,
|
base: webuiPrefix,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue