From 76a8820288778ce892ad2e9880db3d3796674917 Mon Sep 17 00:00:00 2001 From: youdie006 Date: Thu, 29 Oct 2026 12:45:30 +0900 Subject: [PATCH] fix: keep table column alignment in answers ChatGPT's newer answer renderer marks a column written :---, :---: or ---: with data-d-align start, center or end on each of its cells, and a plain column with none (measured 2026-10-29). The reader wrote every separator as ---, so a right-aligned column came back left-aligned. The separator row now follows the header cells' alignment. Verified: a failing test first, then tsc --noEmit and npm test (147 files, 1827 passed, 3 skipped). Live, Instant, branch build: a table with plain, left, center and right columns came back with "| --- | :--- | :---: | ---: |", where 0.40.47 returned four ---. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV --- CHANGELOG.md | 1 + src/chatgpt-browser.ts | 12 ++++++++++-- tests/answer-markdown.test.ts | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1456938a..9b738ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Answers lost their horizontal rules. ChatGPT's newer answer renderer draws a `---` rule as an empty `div[data-d-component=divider]`, and prodex read only `
`, so an answer showing a rule between two sections came back with the sections run together. The rule now comes back as `---`. Found 2026-10-29 comparing a live answer with the page. +- Tables in answers lost their column alignment: a column written `:---`, `:---:` or `---:` came back as `---`, so a right-aligned column of numbers returned left-aligned. ChatGPT's newer answer renderer marks the alignment on each cell (`data-d-align` start, center or end), and the separator row now carries it. Found 2026-10-29 comparing a live answer with the page. ## 0.40.47 diff --git a/src/chatgpt-browser.ts b/src/chatgpt-browser.ts index c0046acb..c6ef8773 100644 --- a/src/chatgpt-browser.ts +++ b/src/chatgpt-browser.ts @@ -627,10 +627,18 @@ export const CHATGPT_RENDERED_MESSAGE_TEXT_JS = ` }; const table = (node) => { const cell = (value) => collapse(value).trim().split("|").join(String.fromCharCode(92) + "|"); - const rows = findAll(node, (n) => tagOf(n) === "tr").map((row) => children(row).filter((c) => c.nodeType === 1).map((c) => cell(inline(c)))); + const cellNodes = findAll(node, (n) => tagOf(n) === "tr").map((row) => children(row).filter((c) => c.nodeType === 1)); + const rows = cellNodes.map((cells) => cells.map((c) => cell(inline(c)))); if (rows.length === 0) return ""; + // The newer renderer marks a column written :---, :---: or ---: with + // data-d-align start, center or end on its cells, and a plain column + // with none (measured 2026-10-29); every column came back as ---. + const rule = (c) => { + const align = attr(c, "data-d-align"); + return align === "start" ? ":---" : align === "center" ? ":---:" : align === "end" ? "---:" : "---"; + }; const line = (cells) => "| " + cells.join(" | ") + " |"; - return [line(rows[0]), line(rows[0].map(() => "---")), ...rows.slice(1).map(line)].join(NL); + return [line(rows[0]), line(cellNodes[0].map(rule)), ...rows.slice(1).map(line)].join(NL); }; const list = (node, depth, keep) => { const ordered = tagOf(node) === "ol"; diff --git a/tests/answer-markdown.test.ts b/tests/answer-markdown.test.ts index f10987ee..abcf05b9 100644 --- a/tests/answer-markdown.test.ts +++ b/tests/answer-markdown.test.ts @@ -157,6 +157,23 @@ describe("page-read answers as markdown", () => { expect(render(root)).toBe("| fruit | color |\n| --- | --- |\n| apple | red |\n| a\\|b | green |"); }); + it("keeps each column's alignment", () => { + // Measured 2026-10-29: the newer renderer marks a column written :---, + // :---: or ---: with data-d-align start, center or end on its cells, and + // a plain column with none. Every column came back as ---. + const cell = (tag: string, value: string, align?: string) => + el(tag, { "data-d-component": "table-cell", ...(align ? { "data-d-align": align } : {}) }, [el("p", {}, [value])]); + const root = el("div", {}, [ + el("table", {}, [ + el("tbody", {}, [ + el("tr", {}, [cell("th", "Plain"), cell("th", "Left", "start"), cell("th", "Center", "center"), cell("th", "Right", "end")]), + el("tr", {}, [cell("td", "a"), cell("td", "b", "start"), cell("td", "c", "center"), cell("td", "d", "end")]) + ]) + ]) + ]); + expect(render(root)).toBe("| Plain | Left | Center | Right |\n| --- | :--- | :---: | ---: |\n| a | b | c | d |"); + }); + it("spells out source pills: a web source as a link, a file source as a label", () => { const web = el("span", { "data-chatgpt-copy-reference": "0" }, [el("a", { href: "https://blog.rust-lang.org/x/" }, ["blog.rust-lang.org"])]); const file = el("span", { "data-chatgpt-copy-reference": "1" }, [el("button", { "aria-label": "cont-att" }, ["cont-att"])]);