An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve `Paste as plain text` when containing HTML tags https://github.com/siyuan-note/siyuan/issues/10620
Danielcea11113929a
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex 20db1e75e9..997316176a 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -7,12 +7,7 @@ import {Constants} from "../../constants";import {highlightRender} from "../render/highlightRender";import {scrollCenter} from "../../util/highlightById";import {updateAttrViewCellAnimation, updateAVName} from "../render/av/action";-import {- genCellValue,- genCellValueByElement,- getTypeByCellElement,- updateCellsValue-} from "../render/av/cell";+import {genCellValue, genCellValueByElement, getTypeByCellElement, updateCellsValue} from "../render/av/cell";import {input} from "../wysiwyg/input";import {objEquals} from "../../util/functions";@@ -213,10 +208,14 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,});}const tempElement = document.createElement("template");- // 需要再 spin 一次 https://github.com/siyuan-note/siyuan/issues/7118- tempElement.innerHTML = tableInlineHTML // 在 table 中插入需要使用转换好的行内元素 https://github.com/siyuan-note/siyuan/issues/9358- || protyle.lute.SpinBlockDOM(html) ||++ let innerHTML = tableInlineHTML || // 在 table 中插入需要使用转换好的行内元素 https://github.com/siyuan-note/siyuan/issues/9358+ protyle.lute.SpinBlockDOM(html) || // 需要再 spin 一次 https://github.com/siyuan-note/siyuan/issues/7118html; // 空格会被 Spin 不再,需要使用原文+ // 粘贴纯文本时会进行内部转义,这里需要进行反转义 https://github.com/siyuan-note/siyuan/issues/10620+ innerHTML = innerHTML.replace(/;;;lt;;;/g, "<").replace(/;;;gt;;;/g, ">");+ tempElement.innerHTML = innerHTML;+const editableElement = getContenteditableElement(blockElement);// 使用 lute 方法会添加 p 元素,只有一个 p 元素或者只有一个字符串或者为 <u>b</u> 时的时候只拷贝内部if (!isBlock) {diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex e2ed3b97ad..2fa2311a63 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -91,7 +91,11 @@ 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/8010navigator.clipboard.readText().then(textPlain => {- insertHTML(protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain)), protyle);+ // 对 HTML 标签进行内部转移,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620+ // 在+ textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");+ const content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));+ insertHTML(content, protyle);filterClipboardHint(protyle, textPlain);});}