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/14114
Vanessa476b3a8467e7
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex e5f606f2e3..5021a999bb 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -309,6 +309,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,if (!blockElement) {return;}+if (blockElement.classList.contains("av")) {range.deleteContents();processAV(range, html, protyle, blockElement as HTMLElement);@@ -318,15 +319,17 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,processTable(range, html, protyle, blockElement)) {return;}+let id = blockElement.getAttribute("data-node-id");range.insertNode(document.createElement("wbr"));let oldHTML = blockElement.outerHTML;const isNodeCodeBlock = blockElement.getAttribute("data-type") === "NodeCodeBlock";+ const editableElement = getContenteditableElement(blockElement);if (!isBlock &&(isNodeCodeBlock || protyle.toolbar.getCurrentType(range).includes("code"))) {range.deleteContents();// 代码块需保持至少一个 \n https://github.com/siyuan-note/siyuan/pull/13271#issuecomment-2502672155- if (isNodeCodeBlock && getContenteditableElement(blockElement).textContent === "") {+ if (isNodeCodeBlock && editableElement.textContent === "") {html += "\n";}range.insertNode(document.createTextNode(html.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));@@ -385,10 +388,18 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,innerHTML = innerHTML.replace(/;;;lt;;;/g, "<").replace(/;;;gt;;;/g, ">");tempElement.innerHTML = innerHTML;- const editableElement = getContenteditableElement(blockElement);+ // https://github.com/siyuan-note/siyuan/issues/14114+ let heading2text = false;+ if (isBlock && editableElement.textContent.replace(Constants.ZWSP, "") !== "" && tempElement.content.childElementCount === 1 &&+ tempElement.content.firstChild.nodeType !== 3 &&+ tempElement.content.firstElementChild.getAttribute("data-type") === "NodeHeading") {+ isBlock = false;+ heading2text = true+ }+// 使用 lute 方法会添加 p 元素,只有一个 p 元素或者只有一个字符串或者为 <u>b</u> 时的时候只拷贝内部if (!isBlock) {- if (tempElement.content.firstChild.nodeType === 3 ||+ if (tempElement.content.firstChild.nodeType === 3 || heading2text ||(tempElement.content.firstChild.nodeType !== 3 &&((tempElement.content.firstElementChild.classList.contains("p") && tempElement.content.childElementCount === 1) ||tempElement.content.firstElementChild.tagName !== "DIV"))) {diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 35da7c722a..5550bdcf40 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -366,14 +366,13 @@ export class WYSIWYG {const tempElement = document.createElement("div");// https://github.com/siyuan-note/siyuan/issues/5540const selectTypes = protyle.toolbar.getCurrentType(range);- if ((selectTypes.length > 0 || range.startContainer.parentElement.parentElement.getAttribute("data-type") === "NodeHeading") &&- (- (range.startContainer.nodeType === 3 && range.startContainer.parentElement.textContent === range.toString()) ||- (range.startContainer.nodeType !== 3 && range.startContainer.textContent === range.toString())- )) {- if (range.startContainer.parentElement.parentElement.getAttribute("data-type") === "NodeHeading") {+ const spanElement = hasClosestByTag(range.startContainer, "SPAN");+ const headingElement = hasClosestByAttribute(range.startContainer, "data-type", "NodeHeading");+ if ((selectTypes.length > 0 && spanElement && spanElement.textContent.replace(Constants.ZWSP, "") === range.toString()) ||+ (headingElement && headingElement.textContent.replace(Constants.ZWSP, "") === range.toString())) {+ if (headingElement) {// 复制标题 https://github.com/siyuan-note/insider/issues/297- tempElement.append(range.startContainer.parentElement.parentElement.cloneNode(true));+ tempElement.append(headingElement.cloneNode(true));} else if (!["DIV", "TD", "TH", "TR"].includes(range.startContainer.parentElement.tagName)) {// 复制行内元素 https://github.com/siyuan-note/insider/issues/191tempElement.append(range.startContainer.parentElement.cloneNode(true));@@ -388,7 +387,8 @@ export class WYSIWYG {} else if (selectImgElement) {html = selectImgElement.outerHTML;textPlain = selectImgElement.querySelector("img").getAttribute("data-src");- } else if (selectTypes.length > 0 && range.startContainer.nodeType === 3 && range.startContainer.parentElement.tagName === "SPAN" &&+ } else if (selectTypes.length > 0 && range.startContainer.nodeType === 3 &&+ range.startContainer.parentElement.tagName === "SPAN" &&range.startContainer.parentElement.isSameNode(range.endContainer.parentElement)) {// 复制粗体等字体中的一部分const attributes = range.startContainer.parentElement.attributes;