Vanessa 2026-01-09 22:25:15 +08:00
parent 8a1c0deb21
commit 03b5067b9e
2 changed files with 9 additions and 6 deletions

View file

@ -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")) {

View file

@ -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) {