33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { renderMessageMarkdown } from "./message-markdown.ts";
|
|
|
|
test("final response markdown supports common blocks and escapes raw html", () => {
|
|
const html = renderMessageMarkdown([
|
|
"# Gateway 控制 Windows CMD 的方法",
|
|
"",
|
|
"核心工具是 `/app/tools/hwlab-gateway-tran.mjs`。",
|
|
"",
|
|
"| 参数 | 作用 |",
|
|
"|---|---|",
|
|
"| `cmd` | 透传 Windows cmd |",
|
|
"",
|
|
"```bash",
|
|
"node /app/tools/hwlab-gateway-tran.mjs gws_DESKTOP-1MHOD9I:/f/work cmd -- pwd",
|
|
"```",
|
|
"",
|
|
"<span class=\"message-copy\">raw html should stay inert</span>",
|
|
"[blocked](javascript:alert(1))",
|
|
""
|
|
].join("\n"));
|
|
|
|
assert.match(html, /<h1>Gateway 控制 Windows CMD 的方法<\/h1>/u);
|
|
assert.match(html, /<table>/u);
|
|
assert.match(html, /<pre><code class="language-bash">/u);
|
|
assert.match(html, /<span class="message-copy">raw html should stay inert<\/span>/u);
|
|
assert.doesNotMatch(html, /<span class="message-copy">/u);
|
|
assert.doesNotMatch(html, /href="javascript:alert\(1\)"/u);
|
|
assert.doesNotMatch(html, /<img\b/u);
|
|
});
|