From 6801b9e373b6db9c0794236693b3f8b3de99ec4f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 5 Apr 2024 22:03:25 +0800 Subject: [PATCH] :art: Improve doc title `Paste as plain text` Fix https://github.com/siyuan-note/siyuan/issues/10866 --- app/src/protyle/header/Title.ts | 9 +++++++-- app/src/protyle/util/paste.ts | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 5c14dbfa5..59c8ffb8f 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -85,8 +85,11 @@ export class Title { } if (matchHotKey("⇧⌘V", event)) { navigator.clipboard.readText().then(textPlain => { + // 对 HTML 标签进行内部转义,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620 textPlain = textPlain.replace(//g, ";;;gt;;;"); - const content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)); + let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)); + // 移除 ;;;lt;;; 和 ;;;gt;;; 转义及其包裹的内容 + content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, ""); document.execCommand("insertText", false, replaceFileName(content)); this.rename(protyle); }); @@ -235,7 +238,9 @@ export class Title { click: async () => { navigator.clipboard.readText().then(textPlain => { textPlain = textPlain.replace(//g, ";;;gt;;;"); - const content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)); + let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)); + // 移除 ;;;lt;;; 和 ;;;gt;;; 转义及其包裹的内容 + content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, ""); document.execCommand("insertText", false, replaceFileName(content)); this.rename(protyle); }); diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 122450122..eb00d9e97 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -168,9 +168,10 @@ 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 => { - // 对 HTML 标签进行内部转移,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620 + // 对 HTML 标签进行内部转义,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620 textPlain = textPlain.replace(//g, ";;;gt;;;"); const content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)); + // insertHTML 会进行内部反转义 insertHTML(content, protyle); filterClipboardHint(protyle, textPlain); });