From cc629041f939e8c610828b62ceeb73c3d282531b Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Fri, 29 Nov 2024 10:18:17 +0800
Subject: [PATCH 1/3] :art: Improve doc title `Paste as plain text`
https://github.com/siyuan-note/siyuan/issues/13301
https://github.com/siyuan-note/siyuan/issues/10866
---
app/src/protyle/header/Title.ts | 7 ++++++-
app/src/protyle/util/paste.ts | 36 ++++++++++++++++++++-------------
app/src/protyle/util/reload.ts | 9 ++-------
3 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index f3e87f089..29cd79c24 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/10620
textPlain = textPlain.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, ";;;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.ts
index 0b77d5c58..1ea6bf344 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, "").replace(/__@\/kbd@__/g, "");
textPlain = textPlain.replace(/__@u@__/g, "").replace(/__@\/u@__/g, "");
- 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.ts
index 50587acf7..883a2ae08 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) {
From 691290a7be30a315e04360b40ef98d0f26e09be9 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Fri, 29 Nov 2024 10:56:32 +0800
Subject: [PATCH 2/3] :art: Add a kernel API `/api/system/getWorkspaceInfo`
https://github.com/siyuan-note/siyuan/issues/13300
---
kernel/api/router.go | 1 +
kernel/api/system.go | 9 +++++++++
kernel/model/session.go | 2 +-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/kernel/api/router.go b/kernel/api/router.go
index c3cc9457e..ec2d5dbd0 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -65,6 +65,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/getNetwork", model.CheckAuth, model.CheckAdminRole, getNetwork)
ginServer.Handle("POST", "/api/system/exportConf", model.CheckAuth, model.CheckAdminRole, exportConf)
ginServer.Handle("POST", "/api/system/importConf", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, importConf)
+ ginServer.Handle("POST", "/api/system/getWorkspaceInfo", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getWorkspaceInfo)
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage)
ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 5f1e66a34..c4eb5cd46 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -35,6 +35,15 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
+func getWorkspaceInfo(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ ret.Data = map[string]any{
+ "workspaceDir": util.WorkspaceDir,
+ }
+}
+
func getNetwork(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
diff --git a/kernel/model/session.go b/kernel/model/session.go
index f51f82a76..a5ff1f121 100644
--- a/kernel/model/session.go
+++ b/kernel/model/session.go
@@ -232,7 +232,7 @@ func CheckAuth(c *gin.Context) {
c.Next()
return
}
- if strings.HasPrefix(c.Request.RequestURI, "/api/system/getNetwork") {
+ if strings.HasPrefix(c.Request.RequestURI, "/api/system/getNetwork") || strings.HasPrefix(c.Request.RequestURI, "/api/system/getWorkspaceInfo") {
c.Set(RoleContextKey, RoleAdministrator)
c.Next()
return
From 041c050d9843b28634a5d437d5d2cef05c91b63f Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Fri, 29 Nov 2024 11:10:00 +0800
Subject: [PATCH 3/3] :art: Add a kernel API `/api/system/getWorkspaceInfo`
https://github.com/siyuan-note/siyuan/issues/13300
---
kernel/api/system.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/api/system.go b/kernel/api/system.go
index c4eb5cd46..b55c128c8 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -41,6 +41,7 @@ func getWorkspaceInfo(c *gin.Context) {
ret.Data = map[string]any{
"workspaceDir": util.WorkspaceDir,
+ "siyuanVer": util.Ver,
}
}