Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +69 -7
templates/index.html
CHANGED
@@ -8,15 +8,20 @@
|
|
8 |
<!-- Tailwind CSS -->
|
9 |
<script src="https://cdn.tailwindcss.com"></script>
|
10 |
|
11 |
-
<!-- React
|
12 |
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
13 |
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
14 |
|
15 |
-
<!-- Babel
|
16 |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
17 |
|
18 |
-
<!--
|
19 |
-
<
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
<!-- Police Space Grotesk -->
|
22 |
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap" rel="stylesheet">
|
@@ -25,6 +30,8 @@
|
|
25 |
body {
|
26 |
font-family: 'Space Grotesk', sans-serif;
|
27 |
}
|
|
|
|
|
28 |
</style>
|
29 |
</head>
|
30 |
<body>
|
@@ -32,7 +39,50 @@
|
|
32 |
|
33 |
<script type="text/babel">
|
34 |
const { useState, useRef, useEffect } = React;
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
function MathSolver() {
|
38 |
const [file, setFile] = useState(null);
|
@@ -46,6 +96,8 @@
|
|
46 |
|
47 |
const timerRef = useRef(null);
|
48 |
const startTimeRef = useRef(null);
|
|
|
|
|
49 |
|
50 |
const handleFileSelect = (selectedFile) => {
|
51 |
if (!selectedFile) return;
|
@@ -68,6 +120,16 @@
|
|
68 |
setElapsed(0);
|
69 |
};
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
const handleSubmit = async (e) => {
|
72 |
e.preventDefault();
|
73 |
if (!file) {
|
@@ -195,13 +257,13 @@
|
|
195 |
{elapsed > 0 && <span className="text-blue-500 text-sm">{elapsed}s</span>}
|
196 |
</button>
|
197 |
<div className={`transition-all duration-300 overflow-hidden ${isThoughtsOpen ? 'max-h-96' : 'max-h-0'}`}>
|
198 |
-
<div className="p-4 text-gray-600 overflow-y-auto"
|
199 |
</div>
|
200 |
</div>
|
201 |
|
202 |
<div className="border-t pt-6">
|
203 |
<h3 className="text-xl font-bold text-gray-800 mb-4">Solution</h3>
|
204 |
-
<div className="text-gray-700 overflow-y-auto max-h-96"
|
205 |
</div>
|
206 |
</div>
|
207 |
)}
|
|
|
8 |
<!-- Tailwind CSS -->
|
9 |
<script src="https://cdn.tailwindcss.com"></script>
|
10 |
|
11 |
+
<!-- React et ReactDOM -->
|
12 |
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
13 |
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
14 |
|
15 |
+
<!-- Babel -->
|
16 |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
17 |
|
18 |
+
<!-- KaTeX -->
|
19 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
|
20 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js"></script>
|
21 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"></script>
|
22 |
+
|
23 |
+
<!-- Marked pour le Markdown -->
|
24 |
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
25 |
|
26 |
<!-- Police Space Grotesk -->
|
27 |
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap" rel="stylesheet">
|
|
|
30 |
body {
|
31 |
font-family: 'Space Grotesk', sans-serif;
|
32 |
}
|
33 |
+
.katex { font-size: 1.1em; }
|
34 |
+
.math-block { margin: 1em 0; }
|
35 |
</style>
|
36 |
</head>
|
37 |
<body>
|
|
|
39 |
|
40 |
<script type="text/babel">
|
41 |
const { useState, useRef, useEffect } = React;
|
42 |
+
|
43 |
+
// Fonction utilitaire pour rendre les formules LaTeX
|
44 |
+
const renderMath = (content, isBlock = false) => {
|
45 |
+
try {
|
46 |
+
return katex.renderToString(content, {
|
47 |
+
displayMode: isBlock,
|
48 |
+
throwOnError: false,
|
49 |
+
strict: false
|
50 |
+
});
|
51 |
+
} catch (e) {
|
52 |
+
console.error('Erreur LaTeX:', e);
|
53 |
+
return content;
|
54 |
+
}
|
55 |
+
};
|
56 |
+
|
57 |
+
// Fonction pour traiter le contenu avec Markdown et LaTeX
|
58 |
+
const processContent = (content) => {
|
59 |
+
// Configuration de marked pour gérer LaTeX
|
60 |
+
const renderer = new marked.Renderer();
|
61 |
+
|
62 |
+
// Gestion des formules en ligne
|
63 |
+
renderer.text = (text) => {
|
64 |
+
return text.replace(/\$([^\$]+)\$/g, (match, latex) => {
|
65 |
+
return renderMath(latex);
|
66 |
+
});
|
67 |
+
};
|
68 |
+
|
69 |
+
// Gestion des blocs de formules
|
70 |
+
renderer.paragraph = (text) => {
|
71 |
+
const blockMathRegex = /\$\$([\s\S]+?)\$\$/g;
|
72 |
+
text = text.replace(blockMathRegex, (match, latex) => {
|
73 |
+
return `<div class="math-block">${renderMath(latex, true)}</div>`;
|
74 |
+
});
|
75 |
+
return `<p>${text}</p>`;
|
76 |
+
};
|
77 |
+
|
78 |
+
marked.setOptions({
|
79 |
+
renderer: renderer,
|
80 |
+
breaks: true,
|
81 |
+
gfm: true
|
82 |
+
});
|
83 |
+
|
84 |
+
return marked(content);
|
85 |
+
};
|
86 |
|
87 |
function MathSolver() {
|
88 |
const [file, setFile] = useState(null);
|
|
|
96 |
|
97 |
const timerRef = useRef(null);
|
98 |
const startTimeRef = useRef(null);
|
99 |
+
const thoughtsRef = useRef(null);
|
100 |
+
const answerRef = useRef(null);
|
101 |
|
102 |
const handleFileSelect = (selectedFile) => {
|
103 |
if (!selectedFile) return;
|
|
|
120 |
setElapsed(0);
|
121 |
};
|
122 |
|
123 |
+
// Mise à jour du contenu avec traitement LaTeX
|
124 |
+
useEffect(() => {
|
125 |
+
if (thoughtsRef.current) {
|
126 |
+
thoughtsRef.current.innerHTML = processContent(thoughts);
|
127 |
+
}
|
128 |
+
if (answerRef.current) {
|
129 |
+
answerRef.current.innerHTML = processContent(answer);
|
130 |
+
}
|
131 |
+
}, [thoughts, answer]);
|
132 |
+
|
133 |
const handleSubmit = async (e) => {
|
134 |
e.preventDefault();
|
135 |
if (!file) {
|
|
|
257 |
{elapsed > 0 && <span className="text-blue-500 text-sm">{elapsed}s</span>}
|
258 |
</button>
|
259 |
<div className={`transition-all duration-300 overflow-hidden ${isThoughtsOpen ? 'max-h-96' : 'max-h-0'}`}>
|
260 |
+
<div ref={thoughtsRef} className="p-4 text-gray-600 overflow-y-auto" />
|
261 |
</div>
|
262 |
</div>
|
263 |
|
264 |
<div className="border-t pt-6">
|
265 |
<h3 className="text-xl font-bold text-gray-800 mb-4">Solution</h3>
|
266 |
+
<div ref={answerRef} className="text-gray-700 overflow-y-auto max-h-96" />
|
267 |
</div>
|
268 |
</div>
|
269 |
)}
|