From b0e9c2d2b93c7545e148f6442a71a8b26c0ac1f6 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Fri, 1 Sep 2023 09:39:05 +0800
Subject: [PATCH 1/2] :bug: Block hyperlinks do not point to regenerated block
IDs when importing .sy.zip https://github.com/siyuan-note/siyuan/issues/9083
---
kernel/model/import.go | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 2b1cb866a..aae449a39 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -170,6 +170,13 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
if "" != newDefID {
n.TextMarkBlockRefID = newDefID
}
+ } else if ast.NodeTextMark == n.Type && n.IsTextMarkType("a") && strings.HasPrefix(n.TextMarkAHref, "siyuan://blocks/") {
+ // Block hyperlinks do not point to regenerated block IDs when importing .sy.zip https://github.com/siyuan-note/siyuan/issues/9083
+ defID := strings.TrimPrefix(n.TextMarkAHref, "siyuan://blocks/")
+ newDefID := blockIDs[defID]
+ if "" != newDefID {
+ n.TextMarkAHref = "siyuan://blocks/" + newDefID
+ }
} else if ast.NodeBlockQueryEmbedScript == n.Type {
for oldID, newID := range blockIDs {
// 导入 `.sy.zip` 后查询嵌入块失效 https://github.com/siyuan-note/siyuan/issues/5316
From 26d5832641f97f7f8cd58e52d3c6f623e854f374 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Fri, 1 Sep 2023 10:47:45 +0800
Subject: [PATCH 2/2] :zap: Improve block loading performance on
Windows/Linux/macOS amd64 arch
https://github.com/siyuan-note/siyuan/issues/9084
---
kernel/filesys/json_parser.go | 39 +++++++++++--------
kernel/filesys/json_unmarshal.go | 36 +++++++++++++++++
.../filesys/json_unmarshal_windows_amd64.go | 34 ++++++++++++++++
kernel/go.mod | 2 +-
4 files changed, 93 insertions(+), 18 deletions(-)
create mode 100644 kernel/filesys/json_unmarshal.go
create mode 100644 kernel/filesys/json_unmarshal_windows_amd64.go
diff --git a/kernel/filesys/json_parser.go b/kernel/filesys/json_parser.go
index bf7a81753..0b5f234e6 100644
--- a/kernel/filesys/json_parser.go
+++ b/kernel/filesys/json_parser.go
@@ -1,12 +1,18 @@
-// Lute - 一款结构化的 Markdown 引擎,支持 Go 和 JavaScript
-// Copyright (c) 2019-present, b3log.org
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
//
-// Lute is licensed under Mulan PSL v2.
-// You can use this software according to the terms and conditions of the Mulan PSL v2.
-// You may obtain a copy of Mulan PSL v2 at:
-// http://license.coscl.org.cn/MulanPSL2
-// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-// See the Mulan PSL v2 for more details.
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
package filesys
@@ -14,17 +20,16 @@ import (
"bytes"
"strings"
+ "github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/editor"
"github.com/88250/lute/parse"
- "github.com/88250/lute/util"
- "github.com/goccy/go-json"
"github.com/siyuan-note/siyuan/kernel/treenode"
)
func ParseJSONWithoutFix(jsonData []byte, options *parse.Options) (ret *parse.Tree, err error) {
root := &ast.Node{}
- err = json.Unmarshal(jsonData, root)
+ err = unmarshalJSON(jsonData, root)
if nil != err {
return
}
@@ -45,7 +50,7 @@ func ParseJSONWithoutFix(jsonData []byte, options *parse.Options) (ret *parse.Tr
func ParseJSON(jsonData []byte, options *parse.Options) (ret *parse.Tree, needFix bool, err error) {
root := &ast.Node{}
- err = json.Unmarshal(jsonData, root)
+ err = unmarshalJSON(jsonData, root)
if nil != err {
return
}
@@ -91,7 +96,7 @@ func ParseJSON(jsonData []byte, options *parse.Options) (ret *parse.Tree, needFi
}
func genTreeByJSON(node *ast.Node, tree *parse.Tree, idMap *map[string]bool, needFix, needMigrate2Spec1 *bool, ignoreFix bool) {
- node.Tokens, node.Type = util.StrToBytes(node.Data), ast.Str2NodeType(node.TypeStr)
+ node.Tokens, node.Type = gulu.Str.ToBytes(node.Data), ast.Str2NodeType(node.TypeStr)
node.Data, node.TypeStr = "", ""
node.KramdownIAL = parse.Map2IAL(node.Properties)
node.Properties = nil
@@ -178,14 +183,14 @@ func fixLegacyData(tip, node *ast.Node, idMap *map[string]bool, needFix, needMig
switch node.Type {
case ast.NodeIFrame:
- if bytes.Contains(node.Tokens, util.StrToBytes("iframe-content")) {
- start := bytes.Index(node.Tokens, util.StrToBytes("