mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-05 00:08:49 +01:00
🎨 Improve HTML underline style clipping https://github.com/siyuan-note/siyuan/issues/14804
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
4b37741535
commit
63a3d64e2f
1 changed files with 14 additions and 4 deletions
|
|
@ -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() === "") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue