This commit is contained in:
Liang Ding 2022-10-25 14:41:29 +08:00
parent 65921ad6d7
commit 420693197d
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 43 additions and 0 deletions

View file

@ -153,6 +153,34 @@ func GetBlockDefIDsByRefText(refText string, excludeIDs []string) (ret []string)
return
}
func GetBlockIndex(id string) (ret int) {
tree, _ := loadTreeByBlockID(id)
if nil == tree {
return
}
node := treenode.GetNodeInTree(tree, id)
if nil == node {
return
}
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if !n.IsChildBlockOf(tree.Root, 1) {
return ast.WalkContinue
}
ret++
if node == n {
return ast.WalkStop
}
return ast.WalkContinue
})
return
}
type BlockPath struct {
ID string `json:"id"`
Name string `json:"name"`