", "").trim() !== "") {
textHTML = textHTML.replace("", "").replace("", "").trim();
if (files && files.length === 1 && (
textHTML.startsWith("
![]()
-1) // Excel 或者浏览器中复制带有图片的表格
)) {
isHTML = false;
} else {
// 需注意 Edge 中的划选不应识别为图片 https://github.com/siyuan-note/siyuan/issues/7021
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: Node | null = null;
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("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf("") &&
0 > textHTMLLowercase.indexOf("") && 0 > textHTMLLowercase.indexOf(""))) {
// 豆包复制粘贴问题 https://github.com/siyuan-note/siyuan/issues/13265 https://github.com/siyuan-note/siyuan/issues/14313
isHTML = false;
}
}
if (isHTML) {
const tempElement = document.createElement("div");
tempElement.innerHTML = textHTML;
// 移除空的 A 标签
tempElement.querySelectorAll("a").forEach((e) => {
if (e.innerHTML.trim() === "") {
e.remove();
}
});
// https://github.com/siyuan-note/siyuan/issues/14625#issuecomment-2869618067
let linkElement;
if (tempElement.childElementCount === 1 && tempElement.childNodes.length === 1) {
if (tempElement.firstElementChild.tagName === "A") {
linkElement = tempElement.firstElementChild;
} else if (tempElement.firstElementChild.tagName === "P" &&
tempElement.firstElementChild.childElementCount === 1 &&
tempElement.firstElementChild.childNodes.length === 1 &&
tempElement.firstElementChild.firstElementChild.tagName === "A") {
linkElement = tempElement.firstElementChild.firstElementChild;
}
}
if (linkElement) {
const selectText = range.toString();
const aElements = protyle.toolbar.setInlineMark(protyle, "a", "range", {
type: "a",
color: `${linkElement.getAttribute("href")}${Constants.ZWSP}${selectText || linkElement.textContent}`
});
if (!selectText) {
if (aElements[0].lastChild) {
// https://github.com/siyuan-note/siyuan/issues/15801
range.setEnd(aElements[0].lastChild, aElements[0].lastChild.textContent.length);
}
range.collapse(false);
}
return;
}
fetchPost("/api/lute/html2BlockDOM", {
dom: tempElement.innerHTML
}, (response) => {
insertHTML(response.data, protyle, false, false, true);
protyle.wysiwyg.element.querySelectorAll('[data-type~="block-ref"]').forEach(item => {
if (item.textContent === "") {
fetchPost("/api/block/getRefText", {id: item.getAttribute("data-id")}, (response) => {
item.innerHTML = response.data;
});
}
});
blockRender(protyle, protyle.wysiwyg.element);
processRender(protyle.wysiwyg.element);
highlightRender(protyle.wysiwyg.element);
avRender(protyle.wysiwyg.element, protyle);
scrollCenter(protyle, undefined, "nearest", "smooth");
});
return;
} else if (files && files.length > 0) {
uploadFiles(protyle, files);
return;
} else if (textPlain.trim() !== "" && (files && files.length === 0 || !files)) {
if (range.toString() !== "") {
const firstLine = textPlain.split("\n")[0];
if (isDynamicRef(textPlain)) {
const refElement = protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
type: "id",
// range 不能 escape,否则 https://github.com/siyuan-note/siyuan/issues/8359
color: `${textPlain.substring(2, 22 + 2)}${Constants.ZWSP}s${Constants.ZWSP}${range.toString()}`
});
if (refElement[0]) {
protyle.toolbar.range.selectNodeContents(refElement[0]);
}
return;
} else if (isFileAnnotation(firstLine)) {
protyle.toolbar.setInlineMark(protyle, "file-annotation-ref", "range", {
type: "file-annotation-ref",
color: firstLine.substring(2).replace(/ ".+">>$/, "")
});
return;
} else {
// https://github.com/siyuan-note/siyuan/issues/8475
const linkDest = textPlain.startsWith("assets/") ? textPlain : protyle.lute.GetLinkDest(textPlain);
if (linkDest) {
protyle.toolbar.setInlineMark(protyle, "a", "range", {
type: "a",
color: linkDest
});
return;
}
}
}
let textPlainDom = protyle.lute.Md2BlockDOM(textPlain);
if (textPlainDom && textPlainDom.indexOf("data:image/") > -1) {
const tempElement = document.createElement("template");
tempElement.innerHTML = textPlainDom;
const imgSrcList: string[] = [];
const imageElements = tempElement.content.querySelectorAll("img");
imageElements.forEach((item) => {
if (item.getAttribute("data-src").startsWith("data:image/")) {
imgSrcList.push(item.getAttribute("data-src"));
}
});
const base64SrcList = await base64ToURL(imgSrcList);
base64SrcList.forEach((item, index) => {
imageElements[index].setAttribute("src", item);
imageElements[index].setAttribute("data-src", item);
imageElements[index].parentElement.querySelector(".img__net")?.remove();
});
textPlainDom = tempElement.innerHTML;
}
insertHTML(textPlainDom, protyle, false, false, true);
}
blockRender(protyle, protyle.wysiwyg.element);
processRender(protyle.wysiwyg.element);
highlightRender(protyle.wysiwyg.element);
avRender(protyle.wysiwyg.element, protyle);
}
const selectCellElement = nodeElement.querySelector(".av__cell--select");
if (nodeElement.classList.contains("av") && selectCellElement) {
cellScrollIntoView(nodeElement, selectCellElement);
} else {
scrollCenter(protyle, undefined, "nearest", "smooth");
}
};