mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Add a kernel API /api/block/getBlockTreeInfos https://github.com/siyuan-note/siyuan/issues/11311
This commit is contained in:
parent
5d47fe4e86
commit
7d73482cfa
4 changed files with 120 additions and 22 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue