"),
"Should render HTML-like tags or their content as text, not hide them",
);
});
it("should render HTML tags in code blocks correctly", () => {
const markdown = new Markdown("```html\nSome HTML
\n```", 0, 0, defaultMarkdownTheme);
const lines = markdown.render(80);
const plainLines = lines.map((line) => line.replace(/\x1b\[[0-9;]*m/g, ""));
const joinedPlain = plainLines.join("\n");
// HTML in code blocks should be visible
assert.ok(
joinedPlain.includes("") && joinedPlain.includes("
"),
"Should render HTML in code blocks",
);
});
});
describe("HTML comments", () => {
// Regression tests for https://github.com/earendil-works/pi/issues/11710
function renderPlain(text: string): string[] {
return new Markdown(text, 0, 0, defaultMarkdownTheme).render(60).map((line) => stripAnsi(line).trimEnd());
}
it("hides block and inline comments without extra spacing", () => {
assert.deepStrictEqual(
renderPlain(
"## [1.0.0]\n\n\nFixed a bug.\n\nSee the docs.",
),
renderPlain("## [1.0.0]\n\nFixed a bug.\n\nSee the docs."),
);
});
it("drops one blank line around comment-only blocks", () => {
assert.deepStrictEqual(
renderPlain(
"\n\n## [1.0.0]\n\n\n\n- item\n\n\n\n## [0.9.0]\n\n",
),
renderPlain("## [1.0.0]\n\n- item\n\n## [0.9.0]"),
);
});
it("hides multi-line and unclosed comments", () => {
assert.deepStrictEqual(renderPlain("\ntext"), renderPlain("text"));
assert.deepStrictEqual(renderPlain("text\n\n\n>\n> r\n\n- a\n\n \n\n b\n- item"),
renderPlain("> q\n>\n> r\n\n- a\n\n b\n- item"),
);
});
it("keeps other HTML and the text after a comment in a block", () => {
assert.deepStrictEqual(renderPlain("with markers"), ["with markers"]);
assert.deepStrictEqual(renderPlain(" trailing text"), ["trailing text"]);
assert.deepStrictEqual(renderPlain("\na
"), ["", "a
"]);
});
});
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);
});
});
});