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/8019
Vanessa4e4398ef471d
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.tsindex bf274bb30f..75bd37c020 100644--- a/app/src/protyle/util/compatibility.ts+++ b/app/src/protyle/util/compatibility.ts@@ -23,24 +23,30 @@ export const encodeBase64 = (text: string): string => {}};-const getSiyuanHTML = (text: IClipboardData) => {- const siyuanMatch = text.textHTML.match(/<!--data-siyuan='([^']+)'-->/);+export const getTextSiyuanFromTextHTML = (html: string) => {+ const siyuanMatch = html.match(/<!--data-siyuan='([^']+)'-->/);+ let textSiyuan = "";+ let textHtml = html;if (siyuanMatch) {try {if (typeof Buffer !== "undefined") {const decodedBytes = Buffer.from(siyuanMatch[1], "base64");- text.siyuanHTML = decodedBytes.toString("utf8");+ textSiyuan = decodedBytes.toString("utf8");} else {const decoder = new TextDecoder();const bytes = Uint8Array.from(atob(siyuanMatch[1]), char => char.charCodeAt(0));- text.siyuanHTML = decoder.decode(bytes);+ textSiyuan = decoder.decode(bytes);}// 移除注释节点,保持原有的 text/html 内容- text.textHTML = text.textHTML.replace(/<!--data-siyuan='[^']+'-->/, "");+ textHtml = html.replace(/<!--data-siyuan='[^']+'-->/, "");} catch (e) {console.log("Failed to decode siyuan data from HTML comment:", e);}}+ return {+ textSiyuan,+ textHtml+ };};export const openByMobile = (uri: string) => {@@ -124,7 +130,9 @@ export const readClipboard = async () => {if (item.types.includes("text/html")) {const blob = await item.getType("text/html");text.textHTML = await blob.text();- getSiyuanHTML(text);+ const textObj = getTextSiyuanFromTextHTML(text.textHTML);+ text.textHTML = textObj.textHtml;+ text.siyuanHTML = textObj.textSiyuan;}if (item.types.includes("text/plain")) {const blob = await item.getType("text/plain");@@ -145,11 +153,15 @@ export const readClipboard = async () => {if (isInAndroid()) {text.textPlain = window.JSAndroid.readClipboard();text.textHTML = window.JSAndroid.readHTMLClipboard();- getSiyuanHTML(text);+ const textObj = getTextSiyuanFromTextHTML(text.textHTML);+ text.textHTML = textObj.textHtml;+ text.siyuanHTML = textObj.textSiyuan;} else if (isInHarmony()) {text.textPlain = window.JSHarmony.readClipboard();text.textHTML = window.JSHarmony.readHTMLClipboard();- getSiyuanHTML(text);+ const textObj = getTextSiyuanFromTextHTML(text.textHTML);+ text.textHTML = textObj.textHtml;+ text.siyuanHTML = textObj.textSiyuan;}return text;}diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex 3fe2db1ac3..f004ac63b8 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -463,10 +463,13 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,foldHeadingId = item.getAttribute("data-node-id");return true;}- if (foldHeadingId && item.getAttribute("parent-heading") === foldHeadingId) {+ if (foldHeadingId && item.getAttribute("parent-heading")) {foldHTML += item.outerHTML;}});+ if (foldHeadingId && foldHTML) {+ fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML});+ }(insertBefore ? Array.from(tempElement.content.children) : Array.from(tempElement.content.children).reverse()).find((item) => {if (item.getAttribute("parent-heading")) {return;diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex 30a942b1e6..2552907aa8 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -1,7 +1,7 @@import {Constants} from "../../constants";import {uploadFiles, uploadLocalFiles} from "../upload";import {processPasteCode, processRender} from "./processCode";-import {getLocalFiles, readText} from "./compatibility";+import {getLocalFiles, getTextSiyuanFromTextHTML, readText} from "./compatibility";import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";import {getEditorRange} from "./selection";import {blockRender} from "../render/blockRender";@@ -288,6 +288,12 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvenif (textPlain.endsWith(Constants.ZWSP) && !textHTML && !siyuanHTML) {siyuanHTML = textPlain.substr(0, textPlain.length - 1);}+ // 复制/剪切折叠标题需获取 siyuanHTML+ if (textHTML && textPlain && !siyuanHTML) {+ const textObj = getTextSiyuanFromTextHTML(textHTML);+ siyuanHTML = textObj.textSiyuan;+ textHTML = textObj.textHtml;+ }// 剪切复制中首位包含空格或仅有空格 https://github.com/siyuan-note/siyuan/issues/5667if (!siyuanHTML) {// process word