This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 00:51:47 -04:00
1 parent e0badc879c
commit cdbd446813
3 files changed
+94 -30

No files matched your search

@@ -51,28 +51,75 @@
{:else if token.type === 'table'}
{@const table = token as Tokens.Table}
<table>
<thead>
<tr>
{#each table.header as cell, i}
<th style={table.align[i] ? `text-align:${table.align[i]}` : ''}>
<InlineRenderer items={cell.tokens} />
</th>
{/each}
</tr>
</thead>
<tbody>
{#each table.rows as row}
<tr>
{#each row as cell, i}
<td style={table.align[i] ? `text-align:${table.align[i]}` : ''}>
<InlineRenderer items={cell.tokens} />
</td>
<div class="not-prose relative w-full group/table">
<div class="overflow-x-auto max-w-full rounded-lg border border-gray-200/60 dark:border-white/8">
<table class="w-full text-[13px] text-left text-gray-600 dark:text-gray-300">
<thead class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50/80 dark:bg-white/[0.03]">
<tr>
{#each table.header as cell, i}
<th
scope="col"
class="px-3 py-1.5 font-medium border-b border-gray-200/60 dark:border-white/8 whitespace-nowrap"
style={table.align[i] ? `text-align:${table.align[i]}` : ''}
>
<InlineRenderer items={cell.tokens} />
</th>
{/each}
</tr>
</thead>
<tbody>
{#each table.rows as row, rowIdx}
<tr class="bg-white dark:bg-transparent">
{#each row as cell, i}
<td
class="px-3 py-1.5 {rowIdx < table.rows.length - 1 ? 'border-b border-gray-100/60 dark:border-white/5' : ''}"
style={table.align[i] ? `text-align:${table.align[i]}` : ''}
>
<InlineRenderer items={cell.tokens} />
</td>
{/each}
</tr>
{/each}
</tr>
{/each}
</tbody>
</table>
</tbody>
</table>
</div>
<!-- Utility buttons (show on hover) -->
<div class="absolute top-1 right-1.5 invisible group-hover/table:visible flex gap-0.5">
<button
class="p-1 rounded text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200/60 dark:hover:bg-white/8 transition-all duration-100"
title="Copy"
onclick={() => {
navigator.clipboard.writeText((token as Tokens.Table).raw?.trim() ?? '');
}}
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75" />
</svg>
</button>
<button
class="p-1 rounded text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200/60 dark:hover:bg-white/8 transition-all duration-100"
title="Download CSV"
onclick={() => {
const t = token as Tokens.Table;
const header = t.header.map(h => `"${h.text.replace(/"/g, '""')}"`);
const rows = t.rows.map(r => r.map(c => `"${c.text.replace(/"/g, '""')}"`));
const csv = [header, ...rows].map(r => r.join(',')).join('\n');
const blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=UTF-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'table.csv';
a.click();
URL.revokeObjectURL(url);
}}
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
</svg>
</button>
</div>
</div>
{:else if token.type === 'hr'}
<hr class="border-gray-100/60 dark:border-gray-850/40" />
@@ -41,6 +41,6 @@
});
</script>
<div class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-th:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 prose-table:my-3 [&>:first-child]:mt-0 [&>:last-child]:mb-0">
<div class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 [&>:first-child]:mt-0 [&>:last-child]:mb-0">
<BlockRenderer {tokens} />
</div>