GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • apps/web/src/components/files
    • FilePreviewPanel.test.ts
    • extendedDocumentPreview.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/files/FilePreviewPanel.test.ts‎

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 numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Third}`;
351351
},
352352
{
353353
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",
355355
},
356356
]);
357357
expect(() => openNotebook(bytes('{"nbformat":3,"cells":[]}'))).toThrow("version 4");
Collapse file

‎apps/web/src/components/files/extendedDocumentPreview.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/files/extendedDocumentPreview.ts
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { XMLParser, XMLValidator } from "fast-xml-parser";
77
import { decodeHTMLAttribute, decodeHTMLStrict as decodeEntities } from "entities";
88
import type JSZip from "jszip";
9+
import { terminalOutputPlainText } from "@t3tools/shared/terminalOutput";
910

1011
import { type OfficeWorkerResult, type NotebookCell } from "./officePreviewProtocol";
1112

@@ -439,12 +440,14 @@ function notebookText(value: unknown, limit = 256_000): string {
439440
if (result.length > limit) throw new Error("A notebook cell is too large to preview.");
440441
return result;
441442
}
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.
443444
function tracebackLines(value: unknown): unknown {
444445
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);
446449
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,
448451
);
449452
}
450453
export function openNotebook(bytes: ArrayBuffer): OfficeWorkerResult {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.