From 63a3d64e2f3ef8e377f20bdab88e705b3bb611c9 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 13 Nov 2025 12:19:06 +0800 Subject: [PATCH] :art: Improve HTML underline style clipping https://github.com/siyuan-note/siyuan/issues/14804 Signed-off-by: Daniel <845765@qq.com> --- app/src/protyle/util/paste.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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() === "") {