import assert from "node:assert/strict"; import { test } from "node:test"; import { renderMarkdown } from "../markdown.ts"; test("escapes raw HTML", () => { const html = renderMarkdown("\n\n"); assert.doesNotMatch(html, / { const html = renderMarkdown("[a](javascript:alert(1)) [b](data:text/html,x) [c](//evil.example) [d](https://ok.example) [e](mailto:x@y.z) [f](#top)"); assert.deepEqual([...html.matchAll(/href="([^"]*)"/g)].map((m) => m[1]), ["#", "#", "#", "https://ok.example", "mailto:x@y.z", "#top"]); }); test("routes relative links and images through the resolver", () => { const html = renderMarkdown("[doc](docs/a.md) ![img](logo.png)", (href, kind) => `/${kind}/${href}`); assert.match(html, /href="\/blob\/docs\/a.md"/); assert.match(html, /src="\/raw\/logo.png"/); });