GeezerVison is showing github.com — fix(web): notebook previews strip ANSI colors from saved tracebacks · pingdotgg/t3code@75a34ed
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/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 |
|
@@ -431,12 +432,14 @@ function notebookText(value: unknown, limit = 256_000): string { |
431 | 432 | if (result.length > limit) throw new Error("A notebook cell is too large to preview."); |
432 | 433 | return result; |
433 | 434 | } |
434 | | -// IPython traceback frames may omit a final newline or follow it with ANSI SGR sequences. |
| 435 | +// IPython traceback frames carry ANSI SGR colors and may omit a final newline. |
435 | 436 | function tracebackLines(value: unknown): unknown { |
436 | 437 | if (!Array.isArray(value)) return value; |
437 | | - const frames = value.filter((frame): frame is string => typeof frame === "string"); |
| 438 | + const frames = value |
| 439 | + .filter((frame): frame is string => typeof frame === "string") |
| 440 | + .map(terminalOutputPlainText); |
438 | 441 | return frames.map((frame, index) => |
439 | | - index && !/\n(?:\u001b\[[\d;:]*m)*$/.test(frames[index - 1]!) ? `\n${frame}` : frame, |
| 442 | + index && !frames[index - 1]!.endsWith("\n") ? `\n${frame}` : frame, |
440 | 443 | ); |
441 | 444 | } |
442 | 445 | export function openNotebook(bytes: ArrayBuffer): OfficeWorkerResult { |
|