Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/14819

Vanessa03b5067b9e36
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index b22a11a8a6..916440d3fb 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -284,7 +284,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
}
}
/// #endif
-
+ const originalTextHTML = textHTML;
// 浏览器地址栏拷贝处理
if (textHTML.replace(/&amp;/g, "&").replace(/<(|\/)(html|body|meta)[^>]*?>/ig, "").trim() ===
`<a href="${textPlain}">${textPlain}</a>` ||
@@ -359,7 +359,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl").forEach(item => {
item.classList.remove("protyle-wysiwyg--hl");
});
- const code = processPasteCode(textHTML, textPlain, protyle);
+ const code = processPasteCode(textHTML, textPlain, originalTextHTML, protyle);
const range = getEditorRange(protyle.wysiwyg.element);
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" ||
protyle.toolbar.getCurrentType(range).includes("code")) {
diff --git a/app/src/protyle/util/processCode.ts b/app/src/protyle/util/processCode.ts
index 1bff7e122b..e413ba1f7f 100644
--- a/app/src/protyle/util/processCode.ts
+++ b/app/src/protyle/util/processCode.ts
@@ -9,7 +9,7 @@ import {plantumlRender} from "../render/plantumlRender";
import {Constants} from "../../constants";
import {htmlRender} from "../render/htmlRender";
-export const processPasteCode = (html: string, text: string, protyle: IProtyle) => {
+export const processPasteCode = (html: string, text: string, originalTextHTML: string, protyle: IProtyle) => {
const tempElement = document.createElement("div");
tempElement.innerHTML = html;
let isCode = false;
@@ -20,13 +20,16 @@ export const processPasteCode = (html: string, text: string, protyle: IProtyle)
} else if (tempElement.childElementCount === 1 && tempElement.querySelectorAll("pre").length === 1) {
// IDE
isCode = true;
- } else if (html.indexOf('\n<p class="p1">') === 0) {
- // Xcode
- isCode = true;
} else if (tempElement.childElementCount === 1 && tempElement.firstElementChild.tagName === "TABLE" &&
tempElement.querySelector(".line-number") && tempElement.querySelector(".line-content")) {
// 网页源码
isCode = true;
+ } else if (originalTextHTML.indexOf('<meta name="Generator" content="Cocoa HTML Writer">') > -1 &&
+ html.indexOf('\n<p class="p1">') === 0 &&
+ // ChatGPT app 目前没有此标识
+ originalTextHTML.indexOf('<style type="text/css">\np.p1') > -1) {
+ // Xcode
+ isCode = true;
}
if (isCode) {