引入正文安全子集并收紧呈现创作口径,避免本局任意脚本美化。
创作只选壳与分区,渲染与提示共用同一份白名单语法。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderMarkdownToHtml } from "../web/markdown.js";
|
||||
|
||||
describe("markdown safe subset render", () => {
|
||||
it("renders GFM tables", () => {
|
||||
const html = renderMarkdownToHtml(
|
||||
["| 甲 | 乙 |", "| --- | --- |", "| 1 | **粗** |"].join("\n"),
|
||||
);
|
||||
expect(html).toContain('<table class="md-table">');
|
||||
expect(html).toContain("<th>");
|
||||
expect(html).toContain("<td>");
|
||||
expect(html).toContain("<strong>粗</strong>");
|
||||
expect(html).not.toContain("| 甲 |");
|
||||
});
|
||||
|
||||
it("renders details folds", () => {
|
||||
const html = renderMarkdownToHtml(
|
||||
[":::details 规则说明", "里面有 *斜体*", ":::"].join("\n"),
|
||||
);
|
||||
expect(html).toContain('<details class="md-details">');
|
||||
expect(html).toContain('<summary class="md-summary">');
|
||||
expect(html).toContain("规则说明");
|
||||
expect(html).toContain("<em>斜体</em>");
|
||||
});
|
||||
|
||||
it("supports open details", () => {
|
||||
const html = renderMarkdownToHtml(
|
||||
[":::details open 已展开", "内容", ":::"].join("\n"),
|
||||
);
|
||||
expect(html).toContain("<details class=\"md-details\" open>");
|
||||
});
|
||||
|
||||
it("escapes raw html tags", () => {
|
||||
const html = renderMarkdownToHtml("<script>alert(1)</script>");
|
||||
expect(html).not.toContain("<script>");
|
||||
expect(html).toContain("<script>");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
formatMarkdownSafeSubsetForPrompt,
|
||||
loadMarkdownSafeSubsetCatalog,
|
||||
parseMarkdownSafeSubsetCatalog,
|
||||
} from "../src/skills/markdown-safe-subset.js";
|
||||
|
||||
const PACK = "dialogue/world-simulator";
|
||||
|
||||
describe("markdown safe subset catalog", () => {
|
||||
it("parses features from yaml", () => {
|
||||
const cat = parseMarkdownSafeSubsetCatalog(`
|
||||
version: 1
|
||||
intro: 测试简介
|
||||
features:
|
||||
- id: table
|
||||
name: 表格
|
||||
syntax: "| a | b |"
|
||||
- id: details
|
||||
name: 折叠
|
||||
syntax: |
|
||||
:::details 标题
|
||||
内容
|
||||
:::
|
||||
restrictions:
|
||||
- 禁止 script
|
||||
`);
|
||||
expect(cat?.features.map((f) => f.id)).toEqual(["table", "details"]);
|
||||
expect(cat?.restrictions).toEqual(["禁止 script"]);
|
||||
});
|
||||
|
||||
it("loads pack catalog with table and details", async () => {
|
||||
const cat = await loadMarkdownSafeSubsetCatalog(PACK);
|
||||
expect(cat).toBeTruthy();
|
||||
const ids = cat!.features.map((f) => f.id);
|
||||
expect(ids).toContain("table");
|
||||
expect(ids).toContain("details");
|
||||
expect(ids).toContain("heading");
|
||||
});
|
||||
|
||||
it("formats injection block for reply-format", async () => {
|
||||
const cat = await loadMarkdownSafeSubsetCatalog(PACK);
|
||||
const block = formatMarkdownSafeSubsetForPrompt(cat!);
|
||||
expect(block).toContain("【正文安全子集】");
|
||||
expect(block).toContain("动态装载");
|
||||
expect(block).toContain("`table`");
|
||||
expect(block).toContain("`details`");
|
||||
expect(block).toContain(":::details");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user