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 doc title `Paste as plain text` https://github.com/siyuan-note/siyuan/issues/13301 https://github.com/siyuan-note/siyuan/issues/10866
Danielcc629041f939
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.tsindex f3e87f089d..29cd79c241 100644--- a/app/src/protyle/header/Title.ts+++ b/app/src/protyle/header/Title.ts@@ -12,7 +12,7 @@ import {MenuItem} from "../../menus/Menu";import {openFileAttr,} from "../../menus/commonMenuItem";import {Constants} from "../../constants";import {matchHotKey} from "../util/hotKey";-import {isMac, readText, writeText} from "../util/compatibility";+import {isMac, readText} from "../util/compatibility";import * as dayjs from "dayjs";import {openFileById} from "../../editor/util";import {setTitle} from "../../dialog/processSystem";@@ -25,6 +25,7 @@ import {hideTooltip} from "../../dialog/tooltip";import {commonClick} from "../wysiwyg/commonClick";import {openTitleMenu} from "./openTitleMenu";import {electronUndo} from "../undo";+import {enableLuteMarkdownSyntax, restoreLuteMarkdownSyntax} from "../util/paste";export class Title {public element: HTMLElement;@@ -77,7 +78,9 @@ export class Title {navigator.clipboard.readText().then(textPlain => {// 对 HTML 标签进行内部转义,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");+ enableLuteMarkdownSyntax(protyle);let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));+ restoreLuteMarkdownSyntax(protyle);// 移除 ;;;lt;;; 和 ;;;gt;;; 转义及其包裹的内容content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");document.execCommand("insertText", false, replaceFileName(content));@@ -229,7 +232,9 @@ export class Title {click: async () => {navigator.clipboard.readText().then(textPlain => {textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");+ enableLuteMarkdownSyntax(protyle);let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));+ restoreLuteMarkdownSyntax(protyle);// 移除 ;;;lt;;; 和 ;;;gt;;; 转义及其包裹的内容content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");document.execCommand("insertText", false, replaceFileName(content));diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex 0b77d5c58b..1ea6bf344a 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -190,21 +190,9 @@ export const pasteAsPlainText = async (protyle: IProtyle) => {textPlain = textPlain.replace(/__@kbd@__/g, "<kbd>").replace(/__@\/kbd@__/g, "</kbd>");textPlain = textPlain.replace(/__@u@__/g, "<u>").replace(/__@\/u@__/g, "</u>");- protyle.lute.SetInlineAsterisk(true);- protyle.lute.SetGFMStrikethrough(true);- protyle.lute.SetInlineMath(true);- protyle.lute.SetSub(true);- protyle.lute.SetSup(true);- protyle.lute.SetTag(true);- protyle.lute.SetInlineUnderscore(true);+ enableLuteMarkdownSyntax(protyle);const content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));- protyle.lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);- protyle.lute.SetGFMStrikethrough(window.siyuan.config.editor.markdown.inlineStrikethrough);- protyle.lute.SetInlineMath(window.siyuan.config.editor.markdown.inlineMath);- protyle.lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);- protyle.lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);- protyle.lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);- protyle.lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);+ restoreLuteMarkdownSyntax(protyle);// insertHTML 会进行内部反转义insertHTML(content, protyle, false, false, true);@@ -213,6 +201,26 @@ export const pasteAsPlainText = async (protyle: IProtyle) => {}};+export const enableLuteMarkdownSyntax = (protyle: IProtyle) => {+ protyle.lute.SetInlineAsterisk(true);+ protyle.lute.SetGFMStrikethrough(true);+ protyle.lute.SetInlineMath(true);+ protyle.lute.SetSub(true);+ protyle.lute.SetSup(true);+ protyle.lute.SetTag(true);+ protyle.lute.SetInlineUnderscore(true);+}++export const restoreLuteMarkdownSyntax = (protyle: IProtyle) => {+ protyle.lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);+ protyle.lute.SetGFMStrikethrough(window.siyuan.config.editor.markdown.inlineStrikethrough);+ protyle.lute.SetInlineMath(window.siyuan.config.editor.markdown.inlineMath);+ protyle.lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);+ protyle.lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);+ protyle.lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);+ protyle.lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);+}+export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element, toBlockDOM = true) => {const range = getEditorRange(protyle.wysiwyg.element);if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.tsindex 50587acf72..883a2ae08b 100644--- a/app/src/protyle/util/reload.ts+++ b/app/src/protyle/util/reload.ts@@ -5,6 +5,7 @@ import {renderBacklink} from "../wysiwyg/renderBacklink";import {hasClosestByClassName} from "./hasClosest";import {preventScroll} from "../scroll/preventScroll";import {searchMarkRender} from "../render/searchMarkRender";+import {restoreLuteMarkdownSyntax} from "./paste";export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?: boolean) => {if (!protyle.preview.element.classList.contains("fn__none")) {@@ -28,13 +29,7 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?}protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);protyle.lute.SetSpellcheck(window.siyuan.config.editor.spellcheck);- protyle.lute.SetInlineAsterisk(window.siyuan.config.editor.markdown.inlineAsterisk);- protyle.lute.SetInlineUnderscore(window.siyuan.config.editor.markdown.inlineUnderscore);- protyle.lute.SetSup(window.siyuan.config.editor.markdown.inlineSup);- protyle.lute.SetSub(window.siyuan.config.editor.markdown.inlineSub);- protyle.lute.SetTag(window.siyuan.config.editor.markdown.inlineTag);- protyle.lute.SetInlineMath(window.siyuan.config.editor.markdown.inlineMath);- protyle.lute.SetGFMStrikethrough(window.siyuan.config.editor.markdown.inlineStrikethrough);+ restoreLuteMarkdownSyntax(protyle);protyle.lute.SetGFMStrikethrough1(false);addLoading(protyle);if (protyle.options.backlinkData) {