fix(tui): stabilize streaming code fence rendering (#5846)

This commit is contained in:
Alexey Zaytsev
2026-06-20 07:58:30 -05:00
committed by GitHub
parent 8b97e75c6b
commit 3095977d13
2 changed files with 69 additions and 0 deletions

View File

@@ -1376,4 +1376,47 @@ bar`,
);
});
});
describe("Streaming code fences", () => {
it("stabilizes partial closing fence rendering", () => {
const cases = [
{
input: "```ts\nconst x = 1;\n``",
expected: ["```ts", " const x = 1;", "```"],
},
{
input: "```md\nnot a closing fence:\n``\n```",
expected: ["```md", " not a closing fence:", " ``", "```"],
},
{
input: "```ts\n``",
expected: ["```ts", "", "```"],
},
{
input: "````\n```",
expected: ["```", "", "```"],
},
{
input: "~~~~~\n~~~~",
expected: ["```", "", "```"],
},
{
input: "```md\nnot a closing fence:\n``\n```\n\nafter",
expected: ["```md", " not a closing fence:", " ``", "```", "", "after"],
},
];
for (const { input, expected } of cases) {
const markdown = new Markdown(input, 0, 0, defaultMarkdownTheme);
const lines = markdown.render(80).map((line) => stripAnsi(line).trimEnd());
assert.deepStrictEqual(lines, expected);
}
const partial = new Markdown("```ts\nconst x = 1;\n``", 0, 0, defaultMarkdownTheme);
const complete = new Markdown("```ts\nconst x = 1;\n```", 0, 0, defaultMarkdownTheme);
assert.strictEqual(partial.render(80).length, complete.render(80).length);
});
});
});