An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/17343
Vanessaf5e740adeeb8
diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.tsindex 295bce074a..c5b3c8e6bc 100644--- a/app/src/protyle/wysiwyg/turnIntoList.ts+++ b/app/src/protyle/wysiwyg/turnIntoList.ts@@ -1,19 +1,21 @@import {transaction, updateTransaction} from "./transaction";import {focusByWbr} from "../util/selection";import * as dayjs from "dayjs";+import {decodeHTML, escapeAttr} from "../../util/escape";export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement: HTMLElement, editElement: HTMLElement, range: Range) => {- const dataTask = editElement.innerHTML.substring(0, 3).match(/^[\[【]([^\x80-\uffff\[\]【】\"])[\]】]$/);+ const html = decodeHTML(editElement.innerHTML);+ const dataTask = html.substring(0, 3).match(/^[\[【]([^\x80-\uffff\[\]【】])[\]】]$/);if (type !== "NodeCodeBlock" &&// 任务列表首块不需要再更新为任务列表!blockElement.previousElementSibling?.classList.contains("protyle-action--task") &&(dataTask ||- ["[]", "【】"].includes(editElement.innerHTML.substring(0, 2))+ ["[]", "【】"].includes(html.substring(0, 2)))) {- const contextStar2tIndex = editElement.innerHTML.indexOf("】") + 1;- let contextStartIndex = editElement.innerHTML.indexOf("]") + 1;+ const contextStar2tIndex = html.indexOf("】") + 1;+ let contextStartIndex = html.indexOf("]") + 1;if (contextStartIndex === 0) {contextStartIndex = contextStar2tIndex;} else if (contextStartIndex > 0 && contextStar2tIndex > 0) {@@ -31,13 +33,13 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:const oldHTML = liElement.outerHTML;liElement.setAttribute("data-subtype", "t");liElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- blockElement.parentElement.setAttribute("data-task", dataTask ? dataTask[1] : " ");+ blockElement.parentElement.setAttribute("data-task", dataTask ? escapeAttr(dataTask[1]) : " ");blockElement.parentElement.setAttribute("data-subtype", "t");if (isDone) {blockElement.parentElement.classList.add("protyle-task--done");}blockElement.previousElementSibling.outerHTML = `<div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>`;- editElement.innerHTML = editElement.innerHTML.substring(contextStartIndex);+ editElement.innerHTML = html.substring(contextStartIndex);updateTransaction(protyle, liElement.getAttribute("data-node-id"), liElement.outerHTML, oldHTML);focusByWbr(protyle.wysiwyg.element, range);return true;@@ -49,7 +51,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:const emptyId = Lute.NewNodeID();const liItemId = Lute.NewNodeID();const oldHTML = blockElement.outerHTML;- editElement.innerHTML = editElement.innerHTML.substring(contextStartIndex);+ editElement.innerHTML = html.substring(contextStartIndex);transaction(protyle, [{action: "update",id,@@ -57,7 +59,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:}, {action: "insert",id: newId,- data: `<div data-subtype="t" data-node-id="${newId}" updated="${newId.split("-")[0]}" data-type="NodeList" class="list"><div data-task="${dataTask ? dataTask[1] : " "}" data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,+ data: `<div data-subtype="t" data-node-id="${newId}" updated="${newId.split("-")[0]}" data-type="NodeList" class="list"><div data-task="${dataTask ? escapeAttr(dataTask[1]) : " "}" data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div><div data-node-id="${emptyId}" data-type="NodeParagraph" class="p"><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}"></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`,previousID: id,}, {action: "move",@@ -78,7 +80,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:id,data: oldHTML,}]);- blockElement.outerHTML = `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list" updated="${newId.split("-")[0]}"><div data-task="${dataTask ? dataTask[1] : " "}" data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`;+ blockElement.outerHTML = `<div data-subtype="t" data-node-id="${newId}" data-type="NodeList" class="list" updated="${newId.split("-")[0]}"><div data-task="${dataTask ? escapeAttr(dataTask[1]) : " "}" data-marker="*" data-subtype="t" data-node-id="${liItemId}" data-type="NodeListItem" class="li${isDone ? " protyle-task--done" : ""}" updated="${liItemId.split("-")[0]}"><div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>${blockElement.outerHTML}<div class="protyle-attr" contenteditable="false"></div></div><div class="protyle-attr" contenteditable="false"></div></div>`;focusByWbr(protyle.wysiwyg.element, range);return true;}diff --git a/app/src/util/escape.ts b/app/src/util/escape.tsindex 41a0f4bb20..6ce933fc66 100644--- a/app/src/util/escape.ts+++ b/app/src/util/escape.ts@@ -23,3 +23,9 @@ export const escapeAriaLabel = (html: string) => {return html.replace(/"/g, """).replace(/'/g, "'").replace(/</g, "&lt;").replace(/</g, "&lt;");};++export const decodeHTML = (html: string) => {+ const txtElement = document.createElement("textarea");+ txtElement.innerHTML = html;+ return txtElement.value;+};