fix(cli): preserve literal HTML text in Markdown tables (#6932)

This commit is contained in:
ShuaixinHuang authored and GitHub committed 2026-10-24 16:11:00 +08:00
1 parent c298d54e88
commit 2c3568c375
3 files changed
+20 -1

No files matched your search

+3
View File
@@ -44,6 +44,9 @@ const isObjectArray = (value: unknown): value is Record<string, unknown>[] =>
const escapeTableCell = (value: string): string =>
value
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\\/g, "\\\\")
.replace(/\|/g, "\\|")
.replace(/\r\n|\r|\n/g, "<br>");
+8
View File
@@ -26,6 +26,14 @@ describe("CLI output argument boundary", () => {
expect(JSON.parse(renderCliDocument(value, "json", false))).toEqual(value);
});
it("preserves literal HTML and entity text in Markdown table headers and cells", () => {
const value = [{ "List<T>": "&copy; <br>\r\nnext" }];
const markdown = renderCliDocument(value, "md", false);
expect(markdown).toContain("List&lt;T&gt;");
expect(markdown).toContain("&amp;copy; &lt;br&gt;<br>next");
expect(JSON.parse(renderCliDocument(value, "json", false))).toEqual(value);
});
it("rejects token windows that would corrupt structured output", () => {
for (const format of ["json", "jsonl", "yaml"] as const) {
const validation = parseCliOutputArguments([
@@ -237,7 +237,11 @@ cliTest(
async ({ cli }) => {
const root = await createTestTempDirectory("rea-evidence-markdown-cells-");
const path = join(root, "bundle.json");
const result = { text: "left|right\\tail\nnext" };
const result = {
text: "left|right\\tail\nnext",
type: "List<string>",
literal: "&copy; <br>",
};
const record = createEvidence(
undefined,
{ id: "fixture", name: "Fixture", version: "1" },
@@ -257,9 +261,13 @@ cliTest(
const json = await cli.run({ arguments: [...base, "--json"] });
expect(json.exitCode, json.stderr).toBe(0);
expect(json.stdout).toContain(JSON.stringify(result.text));
expect(json.stdout).toContain(JSON.stringify(result.type));
expect(json.stdout).toContain(JSON.stringify(result.literal));
const markdown = await cli.run({ arguments: [...base, "--format", "md"] });
expect(markdown.exitCode, markdown.stderr).toBe(0);
expect(markdown.stdout).toContain("left\\|right\\\\tail<br>next");
expect(markdown.stdout).toContain("List&lt;string&gt;");
expect(markdown.stdout).toContain("&amp;copy; &lt;br&gt;");
},
);