Files
pikasTech-HWLAB/web/hwlab-cloud-web/message-markdown.test.ts
T
2026-05-28 21:33:33 +08:00

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))",
"![blocked-image](https://example.invalid/image.png)"
].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, /&lt;span class=&quot;message-copy&quot;&gt;raw html should stay inert&lt;\/span&gt;/u);
assert.doesNotMatch(html, /<span class="message-copy">/u);
assert.doesNotMatch(html, /href="javascript:alert\(1\)"/u);
assert.doesNotMatch(html, /<img\b/u);
});