An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve task checkboxes in database rich text previews
Daniel2a953f6c5d15
diff --git a/app/src/protyle/render/av/richText.test.ts b/app/src/protyle/render/av/richText.test.tsindex 8dfaf2fd8a..223ac02901 100644--- a/app/src/protyle/render/av/richText.test.ts+++ b/app/src/protyle/render/av/richText.test.ts@@ -565,6 +565,33 @@ describe("attribute view rich text DOM policy", () => {assert.match(html, /data-href="https:\/\/b3log\.org\/siyuan"/);});+ it("preserves disabled task checkboxes and nested mixed lists in previews", {+ skip: hasDOM && typeof Lute !== "undefined" ? false :+ "The Node test environment does not provide DOM and Lute globals",+ }, async () => {+ Object.assign(globalThis, {NODE_ENV: "test", SIYUAN_VERSION: "test"});+ const richText = await import("./richText");+ const template = document.createElement("template");+ template.innerHTML = richText.getAVRichTextPreviewHTML([+ "- [ ] pending",+ "- [x] completed",+ " - [ ] nested pending",+ " - ordinary bullet",+ "",+ "1. numbered item",+ ].join("\n"));++ const checkboxes = Array.from(template.content.querySelectorAll<HTMLInputElement>("input"));+ assert.equal(checkboxes.length, 3);+ assert.deepEqual(checkboxes.map((element) => element.checked), [false, true, false]);+ assert.ok(checkboxes.every((element) => element.type === "checkbox" && element.disabled));+ assert.ok(template.content.querySelector("li li input"));+ assert.ok(Array.from(template.content.querySelectorAll("li")).some((element) =>+ element.textContent.trim() === "ordinary bullet" && !element.querySelector("input")));+ assert.equal(template.content.querySelector("ol > li")?.textContent.trim(), "numbered item");+ assert.equal(template.content.querySelector(".protyle-action, svg, use"), null);+ });+it("flattens inline memo HTML and removes dangerous preview links", {skip: hasDOM && typeof Lute !== "undefined" ? false :"The Node test environment does not provide DOM and Lute globals",diff --git a/app/src/protyle/render/av/richText.ts b/app/src/protyle/render/av/richText.tsindex ac1426a174..3fd75daeb7 100644--- a/app/src/protyle/render/av/richText.ts+++ b/app/src/protyle/render/av/richText.ts@@ -340,7 +340,9 @@ export const getAVRichTextBlockDOM = (markdown: string, images = false) => markdconst getAVRichTextPreviewBlockDOM = (blockDOM: string) => {const template = document.createElement("template");template.innerHTML = cleanAVRichTextBlockDOMStructure(blockDOM);- template.content.querySelectorAll(".protyle-action").forEach((element) => element.remove());+ // 待办操作节点携带勾选状态,需要保留到 HTML 转换完成。+ template.content.querySelectorAll(".protyle-action:not(.protyle-action--task)")+ .forEach((element) => element.remove());return (template.innerHTML || "").trim();};