From c36b2a4fdc8759d9762194cd98f738a7bb6525e2 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 16 Feb 2025 16:49:21 +0800 Subject: [PATCH] :art: Improve find-replace of image/link elements https://github.com/siyuan-note/siyuan/issues/14049 --- kernel/model/search.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index e06c3ae43..3a47a698d 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -118,7 +118,7 @@ func ListInvalidBlockRefs(page, pageSize int) (ret []*Block, matchedBlockCount, } var toRemoves []string - for defID, _ := range invalidDefIDs { + for defID := range invalidDefIDs { if _, ok := blockMap[defID]; ok { toRemoves = append(toRemoves, defID) } @@ -148,7 +148,7 @@ func ListInvalidBlockRefs(page, pageSize int) (ret []*Block, matchedBlockCount, delete(refBlockMap, toRemove) } - for refID, _ := range refBlockMap { + for refID := range refBlockMap { invalidBlockIDs = append(invalidBlockIDs, refID) } invalidBlockIDs = gulu.Str.RemoveDuplicatedElem(invalidBlockIDs) @@ -596,6 +596,9 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids } replaceNodeTokens(n, method, keyword, strings.TrimSpace(replacement), r) + if 1 > len(n.Tokens) { + unlinks = append(unlinks, n.Parent) + } case ast.NodeLinkText: if !replaceTypes["imgText"] { return ast.WalkContinue @@ -683,6 +686,10 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids n.TextMarkAHref = r.ReplaceAllString(n.TextMarkAHref, strings.TrimSpace(replacement)) } } + + if "" == n.TextMarkAHref { + unlinks = append(unlinks, n) + } } } else if n.IsTextMarkType("em") { if !replaceTypes["em"] {