mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(media): keep each index.md row on one line and show control characters as escapes (#8127)
The .media/index.md generators (figma's mediaIndex.ts and media-use's index-gen.mjs) turned only CR and LF in a record into a space. Vertical tab, form feed, NEL, U+2028 and U+2029 still ended a row early for readers that treat them as line breaks, and other control characters (NUL, ESC, BEL, C1) reached the file as raw bytes. - Every line-ending character now becomes a space. - Other control characters are written as visible \xNN escapes through the existing terminalText helper; tabs stay as they are. - Both generators and the skill copy change together, so their output stays byte-identical.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { currentRecords, indexPath, ownMediaDir, replaceFile } from "./manifest.mjs";
|
||||
import { terminalText } from "./terminal-text.mjs";
|
||||
|
||||
const LINE_BREAKS = /\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g;
|
||||
|
||||
// One table cell: a line break in a record would start a new line of the index, so it becomes a space.
|
||||
function cell(value) {
|
||||
return String(value ?? "").replace(/\s*[\r\n]+\s*/g, " ");
|
||||
return terminalText(String(value ?? "").replace(LINE_BREAKS, " "));
|
||||
}
|
||||
|
||||
function pad(str, len) {
|
||||
|
||||
@@ -126,17 +126,41 @@ describe("regenerateIndex", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateIndexContent with line breaks in a row", () => {
|
||||
describe("generateIndexContent with line breaks and control characters in a row", () => {
|
||||
const BROKEN_ROWS = [
|
||||
{ ...IMAGE_ROW, id: "image_009\r\n", description: "first line\nsecond line\r\n third" },
|
||||
{ ...ICON_ROW, path: ".media/images/\nicon.svg", description: "\n" },
|
||||
{
|
||||
...IMAGE_ROW,
|
||||
id: "image_010",
|
||||
description: "a\u2028b\u2029c\u0085d\u000be\u000cf",
|
||||
},
|
||||
{
|
||||
...IMAGE_ROW,
|
||||
id: "image_011\u0000",
|
||||
description: "red\u001b[31m\u0007 bell\u007f\u009b\ttab",
|
||||
},
|
||||
];
|
||||
|
||||
it("keeps each row on one line", () => {
|
||||
const lines = generateIndexContent(BROKEN_ROWS).trimEnd().split("\n");
|
||||
const lines = generateIndexContent(BROKEN_ROWS)
|
||||
.trimEnd()
|
||||
.split(/\r\n|[\n\r\v\f\u0085\u2028\u2029]/);
|
||||
// Title, blank line, column heading, then one line per row.
|
||||
expect(lines).toHaveLength(3 + BROKEN_ROWS.length);
|
||||
expect(lines[3]).toContain("first line second line third");
|
||||
expect(lines[5]).toContain("a b c d e f");
|
||||
});
|
||||
|
||||
it("shows other control characters as visible escapes and keeps tabs", () => {
|
||||
const content = generateIndexContent(BROKEN_ROWS);
|
||||
const controls = [...content].filter((ch) => {
|
||||
const code = ch.charCodeAt(0);
|
||||
return (code < 0x20 && code !== 0x09 && code !== 0x0a) || (code >= 0x7f && code <= 0x9f);
|
||||
});
|
||||
expect(controls).toEqual([]);
|
||||
expect(content).toContain("image_011\\x00");
|
||||
expect(content).toContain("red\\x1b[31m\\x07 bell\\x7f\\x9b\ttab");
|
||||
});
|
||||
|
||||
it("matches media-use's index-gen output byte-for-byte", () => {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
import { join } from "node:path";
|
||||
import { replaceFileAtomically } from "../atomicFile";
|
||||
import { terminalText } from "../terminalText";
|
||||
import { readJsonlValues } from "./jsonl";
|
||||
import { manifestPath, mediaDir, ownMediaDir } from "./manifest";
|
||||
|
||||
@@ -22,8 +23,10 @@ export function indexPath(projectDir: string): string {
|
||||
return join(mediaDir(projectDir), "index.md");
|
||||
}
|
||||
|
||||
const LINE_BREAKS = /\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g;
|
||||
|
||||
function singleLineCell(value: unknown): string {
|
||||
return String(value ?? "").replace(/\s*[\r\n]+\s*/g, " ");
|
||||
return terminalText(String(value ?? "").replace(LINE_BREAKS, " "));
|
||||
}
|
||||
|
||||
function pad(str: unknown, len: number): string {
|
||||
|
||||
Reference in New Issue
Block a user