Spaces:
Running on Zero
Running on Zero
feat: add markdown parsing and KaTeX math rendering support to chat messages
Browse files- index.html +37 -3
index.html
CHANGED
|
@@ -7,6 +7,10 @@
|
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet">
|
| 9 |
<script src="https://unpkg.com/lucide@latest"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
<style>
|
| 11 |
:root {
|
| 12 |
--bg: #05070A;
|
|
@@ -440,11 +444,25 @@
|
|
| 440 |
<div class="${bubbleClass} p-6 message-bubble shadow-xl">
|
| 441 |
${mediaHtml}
|
| 442 |
<div class="thinking-container hidden"></div>
|
| 443 |
-
<div class="content-container leading-relaxed text-[15px] whitespace-pre-wrap font-medium">${text}</div>
|
| 444 |
</div>
|
| 445 |
`;
|
| 446 |
|
| 447 |
chatContainer.appendChild(div);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 449 |
return div;
|
| 450 |
}
|
|
@@ -459,12 +477,28 @@
|
|
| 459 |
|
| 460 |
if (thinkingText) {
|
| 461 |
thinkingContainer.classList.remove('hidden');
|
| 462 |
-
thinkingContainer.innerHTML = `<div class="thinking-block">${thinkingText}</div>`;
|
| 463 |
} else {
|
| 464 |
thinkingContainer.classList.add('hidden');
|
| 465 |
}
|
| 466 |
|
| 467 |
-
contentContainer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 469 |
return actualText;
|
| 470 |
}
|
|
|
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet">
|
| 9 |
<script src="https://unpkg.com/lucide@latest"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
| 11 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css">
|
| 12 |
+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js"></script>
|
| 13 |
+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js"></script>
|
| 14 |
<style>
|
| 15 |
:root {
|
| 16 |
--bg: #05070A;
|
|
|
|
| 444 |
<div class="${bubbleClass} p-6 message-bubble shadow-xl">
|
| 445 |
${mediaHtml}
|
| 446 |
<div class="thinking-container hidden"></div>
|
| 447 |
+
<div class="content-container leading-relaxed text-[15px] whitespace-pre-wrap font-medium">${marked.parse(text)}</div>
|
| 448 |
</div>
|
| 449 |
`;
|
| 450 |
|
| 451 |
chatContainer.appendChild(div);
|
| 452 |
+
|
| 453 |
+
const contentContainer = div.querySelector('.content-container');
|
| 454 |
+
if (window.renderMathInElement) {
|
| 455 |
+
renderMathInElement(contentContainer, {
|
| 456 |
+
delimiters: [
|
| 457 |
+
{left: '$$', right: '$$', display: true},
|
| 458 |
+
{left: '$', right: '$', display: false},
|
| 459 |
+
{left: '\\(', right: '\\)', display: false},
|
| 460 |
+
{left: '\\[', right: '\\]', display: true}
|
| 461 |
+
],
|
| 462 |
+
throwOnError: false
|
| 463 |
+
});
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 467 |
return div;
|
| 468 |
}
|
|
|
|
| 477 |
|
| 478 |
if (thinkingText) {
|
| 479 |
thinkingContainer.classList.remove('hidden');
|
| 480 |
+
thinkingContainer.innerHTML = `<div class="thinking-block">${marked.parse(thinkingText)}</div>`;
|
| 481 |
} else {
|
| 482 |
thinkingContainer.classList.add('hidden');
|
| 483 |
}
|
| 484 |
|
| 485 |
+
contentContainer.innerHTML = marked.parse(actualText);
|
| 486 |
+
|
| 487 |
+
// Render Math
|
| 488 |
+
[thinkingContainer, contentContainer].forEach(el => {
|
| 489 |
+
if (window.renderMathInElement) {
|
| 490 |
+
renderMathInElement(el, {
|
| 491 |
+
delimiters: [
|
| 492 |
+
{left: '$$', right: '$$', display: true},
|
| 493 |
+
{left: '$', right: '$', display: false},
|
| 494 |
+
{left: '\\(', right: '\\)', display: false},
|
| 495 |
+
{left: '\\[', right: '\\]', display: true}
|
| 496 |
+
],
|
| 497 |
+
throwOnError: false
|
| 498 |
+
});
|
| 499 |
+
}
|
| 500 |
+
});
|
| 501 |
+
|
| 502 |
chatScrollArea.scrollTo({ top: chatScrollArea.scrollHeight, behavior: 'smooth' });
|
| 503 |
return actualText;
|
| 504 |
}
|