diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index b22a11a8a..916440d3f 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(/&/g, "&").replace(/<(|\/)(html|body|meta)[^>]*?>/ig, "").trim() === `${textPlain}` || @@ -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 1bff7e122..e413ba1f7 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

') === 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('') > -1 && + html.indexOf('\n

') === 0 && + // ChatGPT app 目前没有此标识 + originalTextHTML.indexOf('