From daf964d8d3d9b3f89f886f9c7a5a432d24f8b6a4 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 9 Oct 2024 11:11:47 +0800 Subject: [PATCH] :art: Improve ref count rendering https://github.com/siyuan-note/siyuan/issues/12738 --- kernel/model/block.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/kernel/model/block.go b/kernel/model/block.go index c45595a67..958cdf479 100644 --- a/kernel/model/block.go +++ b/kernel/model/block.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" "github.com/open-spaced-repetition/go-fsrs/v3" @@ -859,13 +860,30 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading // 嵌入块查询结果中显示块引用计数 https://github.com/siyuan-note/siyuan/issues/7191 var defIDs []string for _, n := range nodes { - defIDs = append(defIDs, n.ID) + ast.Walk(n, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering { + return ast.WalkContinue + } + + if n.IsBlock() { + defIDs = append(defIDs, n.ID) + } + return ast.WalkContinue + }) } + defIDs = gulu.Str.RemoveDuplicatedElem(defIDs) refCount := sql.QueryRefCount(defIDs) for _, n := range nodes { - if cnt := refCount[n.ID]; 0 < cnt { - n.SetIALAttr("refcount", strconv.Itoa(cnt)) - } + ast.Walk(n, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering || !n.IsBlock() { + return ast.WalkContinue + } + + if cnt := refCount[n.ID]; 0 < cnt { + n.SetIALAttr("refcount", strconv.Itoa(cnt)) + } + return ast.WalkContinue + }) } luteEngine := NewLute()