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 · pingdotgg/t3code@75a34ed

File tree

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

@@ -431,12 +432,14 @@ function notebookText(value: unknown, limit = 256_000): string {
431432
if (result.length > limit) throw new Error("A notebook cell is too large to preview.");
432433
return result;
433434
}
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.
435436
function tracebackLines(value: unknown): unknown {
436437
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);
438441
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,
440443
);
441444
}
442445
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.