From af42046c919f6354db2a226a93aa46127600a3bb Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 14 Jan 2025 23:04:03 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13796 --- app/src/protyle/util/paste.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 82dd881f6..b3a7846be 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -5,7 +5,7 @@ import {readText} from "./compatibility"; /// #if !BROWSER import {clipboard} from "electron"; /// #endif -import {hasClosestBlock} from "./hasClosest"; +import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "./hasClosest"; import {getEditorRange} from "./selection"; import {blockRender} from "../render/blockRender"; import {highlightRender} from "../render/highlightRender"; @@ -171,6 +171,13 @@ export const pasteAsPlainText = async (protyle: IProtyle) => { if (localFiles.length === 0) { // Inline-level elements support pasted as plain text https://github.com/siyuan-note/siyuan/issues/8010 navigator.clipboard.readText().then(textPlain => { + if (getSelection().rangeCount > 0) { + const range = getSelection().getRangeAt(0) + if (hasClosestByAttribute(range.startContainer, "data-type", "code") || hasClosestByClassName(range.startContainer, "hljs")) { + insertHTML(textPlain.replace(/\u200D```/g, "```").replace(/```/g, "\u200D```"), protyle); + return; + } + } // 对一些内置需要解析的 HTML 标签进行内部转移 Improve sub/sup pasting as plain text https://github.com/siyuan-note/siyuan/issues/12155 textPlain = textPlain.replace(//g, "__@sub@__").replace(/<\/sub>/g, "__@/sub@__"); textPlain = textPlain.replace(//g, "__@sup@__").replace(/<\/sup>/g, "__@/sup@__"); @@ -394,10 +401,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" || protyle.toolbar.getCurrentType(range).includes("code")) { // https://github.com/siyuan-note/siyuan/issues/13552 - textPlain = textPlain.replace(/\u200D```/g, "```"); - textPlain = textPlain.replace(/```/g, "\u200D```"); - - insertHTML(textPlain, protyle); + insertHTML(textPlain.replace(/\u200D```/g, "```").replace(/```/g, "\u200D```"), protyle); return; } else if (siyuanHTML) { // 编辑器内部粘贴