diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 6c880f888..90b137da3 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -470,8 +470,21 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven isHTML = true; } + // 判断是否包含多个换行,包含多个换行则很有可能是纯文本(豆包复制粘贴问题,纯文本外面会包裹一个 HTML 标签,但内部是 Markdown 纯文本) + let containsNewlines = false; + const tempDiv = document.createElement("div"); + tempDiv.innerHTML = textHTML; + const walker = document.createTreeWalker(tempDiv, NodeFilter.SHOW_TEXT, null); + let node; + while (node = walker.nextNode()) { + if (node.nodeValue && (node.nodeValue.match(/\n/g) || []).length >= 2) { + containsNewlines = true; + break; + } + } + const textHTMLLowercase = textHTML.toLowerCase(); - if (textPlain && "" !== textPlain.trim() && (textHTML.startsWith(" textHTMLLowercase.indexOf("class=\"katex") && 0 > textHTMLLowercase.indexOf("class=\"math") && 0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") && @@ -488,9 +501,6 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven if (isHTML) { const tempElement = document.createElement("div"); tempElement.innerHTML = textHTML; - tempElement.querySelectorAll("[style]").forEach((e) => { - e.removeAttribute("style"); - }); // 移除空的 A 标签 tempElement.querySelectorAll("a").forEach((e) => { if (e.innerHTML.trim() === "") {