mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Display reference counts in the backlink panel https://github.com/siyuan-note/siyuan/issues/13618
This commit is contained in:
parent
e643d7106f
commit
ac0bb12dc8
3 changed files with 42 additions and 36 deletions
|
|
@ -19,6 +19,7 @@ package model
|
|||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
|
|
@ -141,6 +142,36 @@ func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func fillBlockRefCount(nodes []*ast.Node) {
|
||||
var defIDs []string
|
||||
for _, n := range nodes {
|
||||
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 {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func renderBlockDOMByNodes(nodes []*ast.Node, luteEngine *lute.Lute) string {
|
||||
tree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
|
||||
blockRenderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue