From 286223db842cbf19796ba8af9fa822385f834fa0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 3 Jul 2025 10:01:04 +0800 Subject: [PATCH] :art: Database index content/markdown values no longer contain zero-width spaces https://github.com/siyuan-note/siyuan/issues/15204 --- kernel/model/blockial.go | 2 ++ kernel/model/virutalref.go | 2 ++ kernel/sql/block.go | 2 ++ kernel/sql/database.go | 6 ++++++ 4 files changed, 12 insertions(+) diff --git a/kernel/model/blockial.go b/kernel/model/blockial.go index 2d64f1bd3..c7637b8f8 100644 --- a/kernel/model/blockial.go +++ b/kernel/model/blockial.go @@ -24,6 +24,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" + "github.com/88250/lute/editor" "github.com/88250/lute/lex" "github.com/88250/lute/parse" "github.com/araddon/dateparse" @@ -69,6 +70,7 @@ func SetBlockReminder(id string, timed string) (err error) { } content := sql.NodeStaticContent(node, nil, false, false, false) content = gulu.Str.SubStr(content, 128) + content = strings.ReplaceAll(content, editor.Zwsp, "") err = SetCloudBlockReminder(id, content, timedMills) if err != nil { return diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index e769ded35..88f7319b3 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -26,6 +26,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute" "github.com/88250/lute/ast" + "github.com/88250/lute/editor" "github.com/88250/lute/parse" "github.com/ClarkThan/ahocorasick" "github.com/dgraph-io/ristretto" @@ -54,6 +55,7 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) { } content := sql.NodeStaticContent(n, nil, false, false, false) + content = strings.ReplaceAll(content, editor.Zwsp, "") buf.WriteString(content) return ast.WalkContinue }) diff --git a/kernel/sql/block.go b/kernel/sql/block.go index 6b9514f38..920ed9995 100644 --- a/kernel/sql/block.go +++ b/kernel/sql/block.go @@ -23,6 +23,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" + "github.com/88250/lute/editor" "github.com/88250/lute/html" "github.com/88250/lute/parse" "github.com/siyuan-note/logging" @@ -117,6 +118,7 @@ func indexNode(tx *sql.Tx, id string) (err error) { } content := NodeStaticContent(node, nil, true, indexAssetPath, true) + content = strings.ReplaceAll(content, editor.Zwsp, "") stmt := "UPDATE blocks SET content = ? WHERE id = ?" if err = execStmtTx(tx, stmt, content, id); err != nil { tx.Rollback() diff --git a/kernel/sql/database.go b/kernel/sql/database.go index f2349d204..e8458cf40 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -36,6 +36,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" + "github.com/88250/lute/editor" "github.com/88250/lute/html" "github.com/88250/lute/parse" "github.com/mattn/go-sqlite3" @@ -867,6 +868,11 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes length = utf8.RuneCountInString(content) } + // 剔除零宽空格 Database index content/markdown values no longer contain zero-width spaces https://github.com/siyuan-note/siyuan/issues/15204 + fcontent = strings.ReplaceAll(fcontent, editor.Zwsp, "") + content = strings.ReplaceAll(content, editor.Zwsp, "") + markdown = strings.ReplaceAll(markdown, editor.Zwsp, "") + block = &Block{ ID: n.ID, ParentID: parentID,