This commit is contained in:
Vanessa 2023-08-04 14:16:47 +08:00
parent c737ecabb6
commit 901ea823cb
8 changed files with 174 additions and 42 deletions

View file

@ -1,7 +1,7 @@
import {Constants} from "../../constants";
import {uploadFiles, uploadLocalFiles} from "../upload";
import {processPasteCode, processRender} from "./processCode";
import {writeText} from "./compatibility";
import {readText, writeText} from "./compatibility";
/// #if !BROWSER
import {clipboard} from "electron";
/// #endif
@ -16,6 +16,43 @@ import {scrollCenter} from "../../util/highlightById";
import {hideElements} from "../ui/hideElements";
import {avRender} from "../render/av/render";
export const pasteEscaped = async (protyle:IProtyle, nodeElement:Element) => {
try {
// * _ [ ] ! \ ` < > & ~ { } ( ) = # $ ^ |
let clipText = await readText();
// https://github.com/siyuan-note/siyuan/issues/5446
// A\B\C\D\
// E
// task-blog-2~default~baiduj 无法原义粘贴含有 `~foo~` 的文本 https://github.com/siyuan-note/siyuan/issues/5523
// 这里必须多加一个反斜杆,因为 Lute 在进行 Markdown 嵌套节点转换平铺标记节点时会剔除 Backslash 节点,
// 多加入的一个反斜杆会作为文本节点保留下来,后续 Spin 时刚好用于转义标记符 https://github.com/siyuan-note/siyuan/issues/6341
clipText = clipText.replace(/\\/g, "\\\\\\\\")
.replace(/\*/g, "\\\\\\*")
.replace(/\_/g, "\\\\\\_")
.replace(/\[/g, "\\\\\\[")
.replace(/\]/g, "\\\\\\]")
.replace(/\!/g, "\\\\\\!")
.replace(/\`/g, "\\\\\\`")
.replace(/\</g, "\\\\\\<")
.replace(/\>/g, "\\\\\\>")
.replace(/\&/g, "\\\\\\&")
.replace(/\~/g, "\\\\\\~")
.replace(/\{/g, "\\\\\\{")
.replace(/\}/g, "\\\\\\}")
.replace(/\(/g, "\\\\\\(")
.replace(/\)/g, "\\\\\\)")
.replace(/\=/g, "\\\\\\=")
.replace(/\#/g, "\\\\\\#")
.replace(/\$/g, "\\\\\\$")
.replace(/\^/g, "\\\\\\^")
.replace(/\|/g, "\\\\\\|");
pasteText(protyle, clipText, nodeElement);
} catch (e) {
console.log(e);
}
}
const filterClipboardHint = (protyle: IProtyle, textPlain: string) => {
let needRender = true;
protyle.options.hint.extend.find(item => {