GeezerVison is showing github.com — fix(web): notebook previews strip ANSI colors from saved tracebacks (… · Pipyakas/t3code@991a564
File tree
Expand file treeCollapse file tree
Open diff view settings
apps/web/src/components/files
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -351,7 +351,7 @@ Third}`; |
351 | 351 | }, |
352 | 352 | { |
353 | 353 | kind: "text", |
354 | | - text: "\u001b[31mTraceback (most recent call last):\n\u001b[0m\u001b[32mCell In[3], line 1\n----> 1 fail()\n\u001b[0m\u001b[39m\u001b[31mValueError: preview proof\u001b[0m\nfinal entry", |
| 354 | + text: "Traceback (most recent call last):\nCell In[3], line 1\n----> 1 fail()\nValueError: preview proof\nfinal entry", |
355 | 355 | }, |
356 | 356 | ]); |
357 | 357 | expect(() => openNotebook(bytes('{"nbformat":3,"cells":[]}'))).toThrow("version 4"); |
|
Collapse file
Copy file name to clipboardExpand all lines: apps/web/src/components/files/extendedDocumentPreview.ts +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
6 | 6 | import { XMLParser, XMLValidator } from "fast-xml-parser"; |
7 | 7 | import { decodeHTMLAttribute, decodeHTMLStrict as decodeEntities } from "entities"; |
8 | 8 | import type JSZip from "jszip"; |
| 9 | +import { terminalOutputPlainText } from "@t3tools/shared/terminalOutput"; |
9 | 10 |
|
10 | 11 | import { type OfficeWorkerResult, type NotebookCell } from "./officePreviewProtocol"; |
11 | 12 |
|
@@ -439,12 +440,14 @@ function notebookText(value: unknown, limit = 256_000): string { |
439 | 440 | if (result.length > limit) throw new Error("A notebook cell is too large to preview."); |
440 | 441 | return result; |
441 | 442 | } |
442 | | -// IPython traceback frames may omit a final newline or follow it with ANSI SGR sequences. |
| 443 | +// IPython traceback frames carry ANSI SGR colors and may omit a final newline. |
443 | 444 | function tracebackLines(value: unknown): unknown { |
444 | 445 | if (!Array.isArray(value)) return value; |
445 | | - const frames = value.filter((frame): frame is string => typeof frame === "string"); |
| 446 | + const frames = value |
| 447 | + .filter((frame): frame is string => typeof frame === "string") |
| 448 | + .map(terminalOutputPlainText); |
446 | 449 | return frames.map((frame, index) => |
447 | | - index && !/\n(?:\u001b\[[\d;:]*m)*$/.test(frames[index - 1]!) ? `\n${frame}` : frame, |
| 450 | + index && !frames[index - 1]!.endsWith("\n") ? `\n${frame}` : frame, |
448 | 451 | ); |
449 | 452 | } |
450 | 453 | export function openNotebook(bytes: ArrayBuffer): OfficeWorkerResult { |
|