feat: add Jupyter Notebook (.ipynb) preview in FileNav

- New NotebookView component renders markdown cells (marked+DOMPurify),
  code cells (Shiki-highlighted with execution count gutter), and
  outputs (text, HTML tables, base64 images, error tracebacks)
- ANSI escape codes stripped from error output
- Source toggle shows raw JSON
- Dark mode support throughout
This commit is contained in:
Timothy Jaeryang Baek committed 2026-03-04 16:14:26 -06:00
1 parent f4c38e6001
commit b081e33c0a
3 files changed
+324 -1

No files matched your search

@@ -8,6 +8,7 @@
import Spinner from '../../common/Spinner.svelte';
import PDFViewer from '../../common/PDFViewer.svelte';
import JsonTreeView from './JsonTreeView.svelte';
import NotebookView from './NotebookView.svelte';
let pdfViewerRef: PDFViewer;
@@ -81,6 +82,7 @@
$: isHtml = HTML_EXTS.has(getExt(selectedFile));
$: isJson = JSON_EXTS.has(getExt(selectedFile));
$: isSvg = getExt(selectedFile) === 'svg';
$: isNotebook = getExt(selectedFile) === 'ipynb';
$: isCode = isCodeFile(selectedFile);
$: csvDelimiter = getExt(selectedFile) === 'tsv' ? '\t' : ',';
$: renderedHtml =
@@ -176,6 +178,19 @@
jsonError = null;
}
// ── Notebook parsing ─────────────────────────────────────────────────
let parsedNotebook: Record<string, unknown> | null = null;
$: if (isNotebook && fileContent !== null) {
try {
parsedNotebook = JSON.parse(fileContent);
} catch {
parsedNotebook = null;
}
} else {
parsedNotebook = null;
}
export let showRaw = false;
$: selectedFile, (showRaw = false); // reset to preview mode when switching files
@@ -352,6 +367,10 @@
</tbody>
</table>
</div>
{:else if isNotebook && !showRaw && parsedNotebook}
<div class="overflow-auto h-full">
<NotebookView notebook={parsedNotebook} />
</div>
{:else if isJson && !showRaw && parsedJson !== undefined}
<div class="overflow-auto h-full">
<JsonTreeView data={parsedJson} />