(rawText: string)
| 78 | const isSeparatorCell = (cell: string) => /^:?-{3,}:?$/.test(cell.trim()); |
| 79 | |
| 80 | function splitAnalysisBlocks(rawText: string): AnalysisBlock[] { |
| 81 | const text = rawText.replace(/\\n/g, "\n"); |
| 82 | const lines = text.split("\n"); |
| 83 | const blocks: AnalysisBlock[] = []; |
| 84 | let markdownBuffer: string[] = []; |
| 85 | const flushMarkdown = () => { if (markdownBuffer.length) { blocks.push({ type: "markdown", content: markdownBuffer.join("\n") }); markdownBuffer = []; } }; |
| 86 | for (let i = 0; i < lines.length; i += 1) { |
| 87 | if (!isTableRow(lines[i])) { markdownBuffer.push(lines[i]); continue; } |
| 88 | flushMarkdown(); |
| 89 | const tableRows: string[][] = []; |
| 90 | while (i < lines.length && isTableRow(lines[i])) { tableRows.push(parseTableRow(lines[i])); i += 1; } |
| 91 | const hasSeparator = tableRows[1]?.every(isSeparatorCell); |
| 92 | if (hasSeparator) tableRows.splice(1, 1); |
| 93 | if (tableRows.length >= 2) blocks.push({ type: "table", rows: tableRows }); |
| 94 | else markdownBuffer.push(...tableRows.map((row) => `| ${row.join(" | ")} |`)); |
| 95 | i -= 1; |
| 96 | } |
| 97 | flushMarkdown(); |
| 98 | return blocks; |
| 99 | } |
| 100 | |
| 101 | function getCache<T>(key: string): Record<string, { data: T; timestamp: number }> { |
| 102 | try { const c = localStorage.getItem(key); return c ? JSON.parse(c) : {}; } catch { return {}; } |
no test coverage detected