Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files289 unmodified lines290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374289 unmodified linesfunction formatAnswer(text) {if (!text) return "";// Split into lines and process eachconst lines = text.split('\n');let html = '';let inTable = false;let tableHtml = '';let inList = false;let listType = '';for (let i = 0; i < lines.length; i++) {let line = lines[i];// Table rowif (line.trim().startsWith('|')) {if (line.match(/^\|[\s\-|]+\|$/)) continue; // skip separator rowsif (!inTable) { tableHtml = '<table class="answer-table">'; inTable = true; }const cells = line.split('|').filter((c, i, a) => i > 0 && i < a.length - 1);const isHeader = i === 0 || !lines[i-1]?.trim().startsWith('|');const tag = isHeader ? 'th' : 'td';tableHtml += '<tr>' + cells.map(c => `<${tag}>${inline(c.trim())}</${tag}>`).join('') + '</tr>';continue;} else if (inTable) {html += tableHtml + '</table>';tableHtml = '';inTable = false;}// Numbered listif (line.match(/^\d+\.\s+/)) {if (!inList || listType !== 'ol') {if (inList) html += `</${listType}>`;html += '<ol>'; inList = true; listType = 'ol';}html += `<li>${inline(line.replace(/^\d+\.\s+/, ''))}</li>`;continue;}// Bullet list (* or -)if (line.match(/^[\*\-]\s+/)) {if (!inList || listType !== 'ul') {if (inList) html += `</${listType}>`;html += '<ul>'; inList = true; listType = 'ul';}html += `<li>${inline(line.replace(/^[\*\-]\s+/, ''))}</li>`;continue;}// Close list if neededif (inList && line.trim() === '') {html += `</${listType}>`;inList = false; listType = '';}// Headersif (line.startsWith('### ')) { html += `<h3>${inline(line.slice(4))}</h3>`; continue; }if (line.startsWith('## ')) { html += `<h2>${inline(line.slice(3))}</h2>`; continue; }if (line.startsWith('# ')) { html += `<h1>${inline(line.slice(2))}</h1>`; continue; }// Empty line = paragraph breakif (line.trim() === '') { html += '<br>'; continue; }// Normal linehtml += `<p>${inline(line)}</p>`;}// Close any open tagsif (inTable) html += tableHtml + '</table>';if (inList) html += `</${listType}>`;return html;}function inline(text) {return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>').replace(/\*(.+?)\*/g, '<em>$1</em>').replace(/`(.+?)`/g, '<code>$1</code>');}function showToast(msg) {289 unmodified lines290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349289 unmodified linesfunction formatAnswer(text) {if (!text) return "";let html = text// Headers.replace(/^### (.+)$/gm, '<h3>$1</h3>').replace(/^## (.+)$/gm, '<h2>$1</h2>').replace(/^# (.+)$/gm, '<h1>$1</h1>')// Bold and italic.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>').replace(/\*(.+?)\*/g, '<em>$1</em>')// Numbered lists.replace(/^\d+\.\s+(.+)$/gm, '<li class="numbered">$1</li>')// Bullet lists.replace(/^[-•]\s+(.+)$/gm, '<li class="bullet">$1</li>')// Tables — | col | col |.replace(/\|(.+)\|/g, (match) => {const cells = match.split('|').filter(c => c.trim());return '<tr>' + cells.map(c =>c.trim().match(/^[-]+$/)? '': `<td>${c.trim()}</td>`).join('') + '</tr>';})// Inline code.replace(/`(.+?)`/g, '<code>$1</code>')// Double newline = paragraph break.replace(/\n\n/g, '</p><p>')// Single newline = line break.replace(/\n/g, '<br>');// Wrap consecutive <li class="numbered"> in <ol>html = html.replace(/(<li class="numbered">.*?<\/li>)+/gs,(match) => `<ol>${match.replace(/class="numbered"/g, '')}</ol>`);// Wrap consecutive <li class="bullet"> in <ul>html = html.replace(/(<li class="bullet">.*?<\/li>)+/gs,(match) => `<ul>${match.replace(/class="bullet"/g, '')}</ul>`);// Wrap table rows in <table>html = html.replace(/(<tr>.*?<\/tr>)+/gs,(match) => `<table class="answer-table">${match}</table>`);return `<p>${html}</p>`;}function showToast(msg) {
frontend/app.js+50-75