Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-11-13 13:06:36 +08:00
commit 3add5302a8
7 changed files with 41 additions and 6 deletions

View file

@ -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("<span") || textHTML.startsWith("<br")) &&
if (textPlain && "" !== textPlain.trim() && (textHTML.startsWith("<span") || textHTML.startsWith("<br")) && containsNewlines &&
(0 > textHTMLLowercase.indexOf("class=\"katex") && 0 > textHTMLLowercase.indexOf("class=\"math") &&
0 > textHTMLLowercase.indexOf("</a>") && 0 > textHTMLLowercase.indexOf("</img>") && 0 > textHTMLLowercase.indexOf("</code>") &&
0 > textHTMLLowercase.indexOf("</b>") && 0 > textHTMLLowercase.indexOf("</strong>") &&
@ -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() === "") {