🐛 Copying blocks without copying attributes on mobile and desktop https://github.com/siyuan-note/siyuan/issues/15268

This commit is contained in:
Daniel 2025-07-13 12:49:51 +08:00
parent 8fb027275a
commit 9f01e38c89
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 3 additions and 4 deletions

View file

@ -374,7 +374,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl").forEach(item => {
item.classList.remove("protyle-wysiwyg--hl");
});
const code = processPasteCode(textHTML, textPlain);
const code = processPasteCode(textHTML, textPlain, protyle);
const range = getEditorRange(protyle.wysiwyg.element);
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" ||
protyle.toolbar.getCurrentType(range).includes("code")) {

View file

@ -9,7 +9,7 @@ import {plantumlRender} from "../render/plantumlRender";
import {Constants} from "../../constants";
import {htmlRender} from "../render/htmlRender";
export const processPasteCode = (html: string, text: string) => {
export const processPasteCode = (html: string, text: string, protyle: IProtyle) => {
const tempElement = document.createElement("div");
tempElement.innerHTML = html;
let isCode = false;
@ -32,8 +32,7 @@ export const processPasteCode = (html: string, text: string) => {
if (isCode) {
let code = text || html;
if (/\n/.test(code)) {
// 不要格式化为多行代码块,否则 Lute 解析会出错 https://github.com/siyuan-note/siyuan/issues/8934
return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span aria-label="${window.siyuan.languages.copy}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
return protyle.lute.Md2BlockDOM(code);
} else {
// Paste code from IDE no longer escape `<` and `>` https://github.com/siyuan-note/siyuan/issues/8340
code = code.replace("<", "&lt;").replace(">", "&gt;");