Spaces:
Runtime error
Runtime error
marked.js for mardown rendering
Browse files8 unmodified lines91011121314291 unmodified lines306307308309310311234 unmodified lines546547548549550551552140 unmodified lines6936946956966976986997 unmodified lines70770870971071171271330 unmodified lines7447457467477487497507517527537547557567577587597607617628 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;234 unmodified linesdata.messages.forEach(msg => {const sender = msg.role === 'user' ? 'user' : 'ai';const el = appendMessage(sender, msg.content);if (sender === 'ai') renderMath(el);});});}140 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});}/* =========================================8 unmodified lines9101112131415291 unmodified lines307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375234 unmodified lines610611612613614615616140 unmodified lines7577587597607617627637 unmodified lines77177277377477577677730 unmodified lines8088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628 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/marked.min.js"></script><style>:root {291 unmodified linesbackground-color: var(--msg-ai);}.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;234 unmodified linesdata.messages.forEach(msg => {const sender = msg.role === 'user' ? 'user' : 'ai';const el = appendMessage(sender, msg.content);if (sender === 'ai') renderContent(el);});});}140 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;// Extract math blocks into placeholders so marked does not mangle themconst mathBlocks = [];let protected_text = raw;// Order matters: extract display math ($$) before inline ($)protected_text = protected_text.replace(/\$\$([\s\S]*?)\$\$/g, (match) => {mathBlocks.push(match);return '%%MATH' + (mathBlocks.length - 1) + '%%';});protected_text = protected_text.replace(/\\\[([\s\S]*?)\\\]/g, (match) => {mathBlocks.push(match);return '%%MATH' + (mathBlocks.length - 1) + '%%';});protected_text = protected_text.replace(/\\\(([\s\S]*?)\\\)/g, (match) => {mathBlocks.push(match);return '%%MATH' + (mathBlocks.length - 1) + '%%';});protected_text = protected_text.replace(/\$([^$\n]+?)\$/g, (match) => {mathBlocks.push(match);return '%%MATH' + (mathBlocks.length - 1) + '%%';});// Parse markdownlet html = marked.parse(protected_text);// Restore math blocksmathBlocks.forEach((block, i) => {html = html.replace('%%MATH' + i + '%%', block);});element.innerHTML = html;// Run KaTeX on the rendered HTMLif (typeof renderMathInElement !== 'undefined') {renderMathInElement(element, {delimiters: [{left: '$$', right: '$$', display: true},{left: '$', right: '$', display: false},{left: '\\(', right: '\\)', display: false},{left: '\\[', right: '\\]', display: true}],throwOnError: false});}}/* =========================================
stem.html+114-14