mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-21 19:41:05 +08: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
@ -199,12 +199,12 @@ func sortBacklinks(backlinks []*Backlink, tree *parse.Tree) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlight bool, luteEngine *lute.Lute) (ret *Backlink) {
|
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlight bool, luteEngine *lute.Lute) (ret *Backlink) {
|
||||||
n := treenode.GetNodeInTree(refTree, refID)
|
node := treenode.GetNodeInTree(refTree, refID)
|
||||||
if nil == n {
|
if nil == node {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
renderNodes, expand := getBacklinkRenderNodes(n)
|
renderNodes, expand := getBacklinkRenderNodes(node)
|
||||||
|
|
||||||
if highlight && 0 < len(keywords) {
|
if highlight && 0 < len(keywords) {
|
||||||
for _, renderNode := range renderNodes {
|
for _, renderNode := range renderNodes {
|
||||||
@ -229,15 +229,18 @@ func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 反链面板中显示块引用计数 Display reference counts in the backlink panel https://github.com/siyuan-note/siyuan/issues/13618
|
||||||
|
fillBlockRefCount(renderNodes)
|
||||||
|
|
||||||
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
||||||
var blockPaths []*BlockPath
|
var blockPaths []*BlockPath
|
||||||
if (nil != n.Parent && ast.NodeDocument != n.Parent.Type) || (ast.NodeHeading != n.Type && 0 < treenode.HeadingLevel(n)) {
|
if (nil != node.Parent && ast.NodeDocument != node.Parent.Type) || (ast.NodeHeading != node.Type && 0 < treenode.HeadingLevel(node)) {
|
||||||
blockPaths = buildBlockBreadcrumb(n, nil, false)
|
blockPaths = buildBlockBreadcrumb(node, nil, false)
|
||||||
}
|
}
|
||||||
if 1 > len(blockPaths) {
|
if 1 > len(blockPaths) {
|
||||||
blockPaths = []*BlockPath{}
|
blockPaths = []*BlockPath{}
|
||||||
}
|
}
|
||||||
ret = &Backlink{DOM: dom, BlockPaths: blockPaths, Expand: expand, node: n}
|
ret = &Backlink{DOM: dom, BlockPaths: blockPaths, Expand: expand, node: node}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/88250/lute/render"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/88250/lute/render"
|
||||||
"github.com/open-spaced-repetition/go-fsrs/v3"
|
"github.com/open-spaced-repetition/go-fsrs/v3"
|
||||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
@ -902,33 +900,7 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 嵌入块查询结果中显示块引用计数 https://github.com/siyuan-note/siyuan/issues/7191
|
// 嵌入块查询结果中显示块引用计数 https://github.com/siyuan-note/siyuan/issues/7191
|
||||||
var defIDs []string
|
fillBlockRefCount(nodes)
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
luteEngine.RenderOptions.ProtyleContenteditable = false // 不可编辑
|
luteEngine.RenderOptions.ProtyleContenteditable = false // 不可编辑
|
||||||
|
@ -19,6 +19,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
@ -141,6 +142,36 @@ func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
|
|||||||
return
|
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 {
|
func renderBlockDOMByNodes(nodes []*ast.Node, luteEngine *lute.Lute) string {
|
||||||
tree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
|
tree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
|
||||||
blockRenderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions)
|
blockRenderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions)
|
||||||
|
Loading…
Reference in New Issue
Block a user