import { expect, test } from "bun:test";
import { renderMarkdown } from "../src/ui/markdown";
test("headings, paragraphs, emphasis, inline code", () => {
expect(renderMarkdown("# Title\n\nSome **bold** and *em* and `x < y`.\nSecond line.")).toBe(
'
Title
\nSome bold and em and x < y.\nSecond line.
',
);
});
test("raw HTML is escaped, except the details/summary hint blocks", () => {
expect(renderMarkdown("")).toBe("<script>alert(1)</script>
");
const h = renderMarkdown("\nExercise 1 — nudge
\n\nTry **this**.\n\n ");
expect(h).toMatch(/\s*Exercise 1 — nudge<\/summary>/);
expect(h).toContain("Try this.
");
expect(h).toContain("
");
expect(renderMarkdown("a")).not.toContain(" {
expect(renderMarkdown("```js\nconst a = '';\n# not a heading\n```")).toBe(
'const a = \'<b>\';\n# not a heading
',
);
});
test("lists, quotes, rules", () => {
expect(renderMarkdown("- a\n- b\n\n1. one\n2. two")).toBe("\n- one
- two
");
expect(renderMarkdown("> quoted\n\n---")).toBe("quoted
\n
");
});
test("links: safe schemes only; images resolved through the given resolver", () => {
expect(renderMarkdown("[ok](https://x.org/a?b=1&c=2)")).toBe('ok
');
expect(renderMarkdown("[bad](javascript:alert(1))")).toBe("bad
");
expect(renderMarkdown("", { resolveUrl: (u) => `/raw/${encodeURIComponent(u)}` })).toBe('
');
});
test("front matter is not rendered", () => {
expect(renderMarkdown("---\ntitle: x\n---\n# H")).toBe('H
');
});