Spaces:
Runtime error
Runtime error
katex expression
Browse files8 unmodified lines9101112131415291 unmodified lines307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370113 unmodified lines484485486487488489490121 unmodified lines612613614615616617618143 unmodified lines7627637647657667677687 unmodified lines77677777877978078178230 unmodified lines8138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708 unmodified lines<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"></script><script src="https://cdn.jsdelivr.net/npm/marked@13.0.6/marked.min.js"></script><style>:root {291 unmodified linesbackground-color: var(--msg-ai);}/* Markdown styles for AI messages */.ai .message-content h1,.ai .message-content h2,.ai .message-content h3 {margin: 16px 0 8px 0;line-height: 1.3;}.ai .message-content h1 { font-size: 1.4em; }.ai .message-content h2 { font-size: 1.2em; }.ai .message-content h3 { font-size: 1.05em; }.ai .message-content p { margin: 8px 0; }.ai .message-content ul,.ai .message-content ol {margin: 8px 0;padding-left: 24px;}.ai .message-content li { margin: 4px 0; }.ai .message-content code {background-color: #1a1a1a;padding: 2px 6px;border-radius: 4px;font-size: 0.9em;font-family: 'Courier New', monospace;}.ai .message-content pre {background-color: #111111;padding: 12px 16px;border-radius: 8px;overflow-x: auto;margin: 10px 0;}.ai .message-content pre code {background: none;padding: 0;}.ai .message-content hr {border: none;border-top: 1px solid var(--border-color);margin: 12px 0;}.ai .message-content strong { font-weight: 600; }.ai .message-content blockquote {border-left: 3px solid var(--brand-orange);padding-left: 12px;margin: 8px 0;color: var(--text-secondary);}.ai-avatar {width: 30px;height: 30px;113 unmodified lines::-webkit-scrollbar-thumb:hover { background: #555; }.cursor::after {content: '\u25CB';animation: blink 1s step-start infinite;color: var(--text-secondary);margin-left: 2px;121 unmodified linesdata.messages.forEach(msg => {const sender = msg.role === 'user' ? 'user' : 'ai';const el = appendMessage(sender, msg.content);if (sender === 'ai') renderContent(el);});});}143 unmodified linesreader.read().then(({done, value}) => {if (done) {contentElement.classList.remove('cursor');renderContent(contentElement);isSending = false;return;}7 unmodified linesconst payload = line.substring(6);if (payload === '[DONE]') {contentElement.classList.remove('cursor');renderContent(contentElement);isSending = false;return;}30 unmodified lines}/* =========================================Markdown + Math Rendering========================================= */function renderContent(element) {const raw = element.textContent;// Step 1: Extract math blocks into placeholders so marked does not mangle themconst mathBlocks = [];let safeText = raw;// Display math: $$ ... $$safeText = safeText.replace(/\$\$([\s\S]*?)\$\$/g, function(match) {mathBlocks.push(match);return 'MATHBLOCK' + (mathBlocks.length - 1) + 'END';});// Display math: \[ ... \]safeText = safeText.replace(/\\\[([\s\S]*?)\\\]/g, function(match) {mathBlocks.push(match);return 'MATHBLOCK' + (mathBlocks.length - 1) + 'END';});// Inline math: \( ... \)safeText = safeText.replace(/\\\(([\s\S]*?)\\\)/g, function(match) {mathBlocks.push(match);return 'MATHBLOCK' + (mathBlocks.length - 1) + 'END';});// Inline math: $ ... $ (single line, not greedy)safeText = safeText.replace(/\$([^\$\n]+?)\$/g, function(match) {mathBlocks.push(match);return 'MATHBLOCK' + (mathBlocks.length - 1) + 'END';});// Step 2: Parse markdownvar html = marked.parse(safeText);// Step 3: Restore math blocksfor (var i = 0; i < mathBlocks.length; i++) {html = html.replace('MATHBLOCK' + i + 'END', mathBlocks[i]);}element.innerHTML = html;// Step 4: Run KaTeX on the resultif (typeof renderMathInElement !== 'undefined') {renderMathInElement(element, {delimiters: [{left: '$$', right: '$$', display: true},{left: '$', right: '$', display: false},{left: '\\(', right: '\\)', display: false},{left: '\\[', right: '\\]', display: true}],throwOnError: false});}}/* =========================================8 unmodified lines91011121314291 unmodified lines306307308309310311113 unmodified lines425426427428429430431121 unmodified lines553554555556557558559143 unmodified lines7037047057067077087097 unmodified lines71771871972072172272330 unmodified lines7547557567577587597607617627637647657667677687697707717728 unmodified lines<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"></script><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"></script><style>:root {291 unmodified linesbackground-color: var(--msg-ai);}.ai-avatar {width: 30px;height: 30px;113 unmodified lines::-webkit-scrollbar-thumb:hover { background: #555; }.cursor::after {content: '▋';animation: blink 1s step-start infinite;color: var(--text-secondary);margin-left: 2px;121 unmodified linesdata.messages.forEach(msg => {const sender = msg.role === 'user' ? 'user' : 'ai';const el = appendMessage(sender, msg.content);if (sender === 'ai') renderMath(el);});});}143 unmodified linesreader.read().then(({done, value}) => {if (done) {contentElement.classList.remove('cursor');renderMath(contentElement);isSending = false;return;}7 unmodified linesconst payload = line.substring(6);if (payload === '[DONE]') {contentElement.classList.remove('cursor');renderMath(contentElement);isSending = false;return;}30 unmodified lines}/* =========================================Math Rendering (KaTeX)========================================= */function renderMath(element) {if (typeof renderMathInElement === 'undefined') return;renderMathInElement(element, {delimiters: [{left: '$$', right: '$$', display: true},{left: '$', right: '$', display: false},{left: '\\(', right: '\\)', display: false},{left: '\\[', right: '\\]', display: true}],throwOnError: false});}/* =========================================
stem.html+15-113