🎨 Add a kernel API /api/block/getBlockTreeInfos https://github.com/siyuan-note/siyuan/issues/11311

This commit is contained in:
Daniel 2024-05-09 23:20:28 +08:00
parent 5d47fe4e86
commit 7d73482cfa
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 120 additions and 22 deletions

View file

@ -401,6 +401,39 @@ func ParentBlock(node *ast.Node) *ast.Node {
return nil
}
func PreviousBlock(node *ast.Node) *ast.Node {
for n := node.Previous; nil != n; n = n.Previous {
if "" != n.ID && n.IsBlock() {
return n
}
}
return nil
}
func NextBlock(node *ast.Node) *ast.Node {
for n := node.Next; nil != n; n = n.Next {
if "" != n.ID && n.IsBlock() {
return n
}
}
return nil
}
func FirstChildBlock(node *ast.Node) (ret *ast.Node) {
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if n.IsBlock() {
ret = n
return ast.WalkStop
}
return ast.WalkContinue
})
return
}
func GetNodeInTree(tree *parse.Tree, id string) (ret *ast.Node) {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {