feat: 代码片段功能与 Markdown 内嵌片段渲染、文档截图等
This commit is contained in:
@@ -14,6 +14,8 @@ import {
|
||||
pagePath,
|
||||
parseEntityPath,
|
||||
postPath,
|
||||
snippetPath,
|
||||
snippetsPath,
|
||||
userPath,
|
||||
} from "./urlStyle.ts";
|
||||
|
||||
@@ -89,6 +91,16 @@ describe("路径构造器", () => {
|
||||
assert.equal(entityPath("default", "user", 9), "/u/9");
|
||||
assert.equal(entityPath("html", "announcement", 9), "/announcement-9.html");
|
||||
});
|
||||
it("代码片段三风格(html/discuz 同模板)", () => {
|
||||
assert.equal(snippetsPath("default"), "/snippets");
|
||||
assert.equal(snippetsPath("html"), "/snippets.html");
|
||||
assert.equal(snippetsPath("discuz"), "/snippets.html");
|
||||
assert.equal(snippetPath("default", 12), "/snippets/12");
|
||||
assert.equal(snippetPath("html", 12), "/snippet-12.html");
|
||||
assert.equal(snippetPath("discuz", 12), "/snippet-12.html");
|
||||
assert.equal(snippetPath("default", 0), "");
|
||||
assert.equal(snippetPath("html", -1), "");
|
||||
});
|
||||
it("评论锚点使用帖内相对楼层号", () => {
|
||||
assert.equal(commentAnchor(1, true, 147), "#comment-1");
|
||||
assert.equal(commentAnchor(3, false, 147), "#comment-3-r147");
|
||||
@@ -111,6 +123,14 @@ describe("matchPrettyPath", () => {
|
||||
assert.deepEqual(matchPrettyPath("/p-about.html"), { style: "html", kind: "page", slug: "about" });
|
||||
assert.deepEqual(matchPrettyPath("/leaderboard.html"), { style: "html", kind: "leaderboard" });
|
||||
assert.deepEqual(matchPrettyPath("/rank.html"), { style: "discuz", kind: "leaderboard" });
|
||||
assert.deepEqual(matchPrettyPath("/snippets.html", "html"), { style: "html", kind: "snippets" });
|
||||
assert.deepEqual(matchPrettyPath("/snippets.html", "discuz"), { style: "discuz", kind: "snippets" });
|
||||
assert.deepEqual(matchPrettyPath("/snippet-12.html", "discuz"), { style: "discuz", kind: "snippet", id: 12 });
|
||||
assert.deepEqual(matchPrettyPath("/snippet-12.html"), { style: "html", kind: "snippet", id: 12 });
|
||||
assert.equal(matchPrettyPath("/snippet-abc.html"), null);
|
||||
assert.equal(matchPrettyPath("/snippet-.html"), null);
|
||||
assert.equal(matchPrettyPath("/snippets-.html"), null);
|
||||
assert.equal(matchPrettyPath("/snippet-12.htmlx"), null);
|
||||
});
|
||||
it("书库两风格同模板:prefer 优先当前风格,缺省首条兜底", () => {
|
||||
assert.equal(matchPrettyPath("/library.html", "html")?.style, "html");
|
||||
@@ -187,6 +207,13 @@ describe("matchStandardPath / parseEntityPath", () => {
|
||||
assert.deepEqual(matchStandardPath("/library/abc/read"), { kind: "libraryRead", slug: "abc" });
|
||||
assert.equal(matchStandardPath("/library/a/b"), null);
|
||||
assert.equal(matchStandardPath("/libraryx"), null);
|
||||
// 片段:列表与详情;new/edit 子路径不得命中详情
|
||||
assert.deepEqual(matchStandardPath("/snippets"), { kind: "snippets" });
|
||||
assert.deepEqual(matchStandardPath("/snippets/"), { kind: "snippets" });
|
||||
assert.deepEqual(matchStandardPath("/snippets/12"), { kind: "snippet", id: 12 });
|
||||
assert.equal(matchStandardPath("/snippets/new"), null);
|
||||
assert.equal(matchStandardPath("/snippets/12/edit"), null);
|
||||
assert.equal(matchStandardPath("/snippetsx"), null);
|
||||
});
|
||||
it("parseEntityPath 兼容标准与全部模板", () => {
|
||||
assert.deepEqual(parseEntityPath("/post/12"), { kind: "post", id: 12 });
|
||||
@@ -211,4 +238,10 @@ describe("matchStandardPath / parseEntityPath", () => {
|
||||
assert.deepEqual(parseEntityPath("/library/abc/read"), { kind: "libraryRead", slug: "abc" });
|
||||
assert.deepEqual(parseEntityPath("/library-abc-read-2.html"), { kind: "libraryRead", slug: "abc" });
|
||||
});
|
||||
it("parseEntityPath 兼容片段路径", () => {
|
||||
assert.deepEqual(parseEntityPath("/snippets"), { kind: "snippets" });
|
||||
assert.deepEqual(parseEntityPath("/snippets/12"), { kind: "snippet", id: 12 });
|
||||
assert.deepEqual(parseEntityPath("/snippets.html"), { kind: "snippets" });
|
||||
assert.deepEqual(parseEntityPath("/snippet-12.html"), { kind: "snippet", id: 12 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user