Skip to content

Commit

Permalink
🎨 #13796
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 14, 2025
1 parent cffec4b commit af42046
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/src/protyle/util/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(/<sub>/g, "__@sub@__").replace(/<\/sub>/g, "__@/sub@__");
textPlain = textPlain.replace(/<sup>/g, "__@sup@__").replace(/<\/sup>/g, "__@/sup@__");
Expand Down Expand Up @@ -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) {
// 编辑器内部粘贴
Expand Down

0 comments on commit af42046

Please sign in to comment.