mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-14 03:04:21 +01:00
🎨 Add internal kernel API /api/block/getTailChildBlocks https://github.com/siyuan-note/siyuan/issues/9884
This commit is contained in:
parent
e6aeb5c5cd
commit
a16fde8ae7
3 changed files with 81 additions and 0 deletions
|
|
@ -546,6 +546,60 @@ func GetChildBlocks(id string) (ret []*ChildBlock) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetTailChildBlocks(id string, n int) (ret []*ChildBlock) {
|
||||
ret = []*ChildBlock{}
|
||||
if "" == id {
|
||||
return
|
||||
}
|
||||
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
return
|
||||
}
|
||||
|
||||
if ast.NodeHeading == node.Type {
|
||||
children := treenode.HeadingChildren(node)
|
||||
for i := len(children) - 1; 0 <= i; i-- {
|
||||
c := children[i]
|
||||
ret = append(ret, &ChildBlock{
|
||||
ID: c.ID,
|
||||
Type: treenode.TypeAbbr(c.Type.String()),
|
||||
SubType: treenode.SubTypeAbbr(c),
|
||||
})
|
||||
if n == len(ret) {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if !node.IsContainerBlock() {
|
||||
return
|
||||
}
|
||||
|
||||
for c := node.LastChild; nil != c; c = c.Previous {
|
||||
if !c.IsBlock() {
|
||||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, &ChildBlock{
|
||||
ID: c.ID,
|
||||
Type: treenode.TypeAbbr(c.Type.String()),
|
||||
SubType: treenode.SubTypeAbbr(c),
|
||||
})
|
||||
|
||||
if n == len(ret) {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetBlock(id string, tree *parse.Tree) (ret *Block, err error) {
|
||||
ret, err = getBlock(id, tree)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue