mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
🧑💻 Improve kernel API getChildBlocks https://github.com/siyuan-note/siyuan/issues/12260 https://github.com/siyuan-note/siyuan/issues/8249
This commit is contained in:
parent
3c0c24e3a7
commit
f5e5816997
1 changed files with 29 additions and 15 deletions
|
@ -636,9 +636,11 @@ func GetBlockKramdown(id string) (ret string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChildBlock struct {
|
type ChildBlock struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
SubType string `json:"subType,omitempty"`
|
SubType string `json:"subType,omitempty"`
|
||||||
|
Content string `json:"content,omitempty"`
|
||||||
|
Markdown string `json:"markdown,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetChildBlocks(id string) (ret []*ChildBlock) {
|
func GetChildBlocks(id string) (ret []*ChildBlock) {
|
||||||
|
@ -660,10 +662,13 @@ func GetChildBlocks(id string) (ret []*ChildBlock) {
|
||||||
if ast.NodeHeading == node.Type {
|
if ast.NodeHeading == node.Type {
|
||||||
children := treenode.HeadingChildren(node)
|
children := treenode.HeadingChildren(node)
|
||||||
for _, c := range children {
|
for _, c := range children {
|
||||||
|
block := sql.BuildBlockFromNode(c, tree)
|
||||||
ret = append(ret, &ChildBlock{
|
ret = append(ret, &ChildBlock{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: treenode.TypeAbbr(c.Type.String()),
|
Type: treenode.TypeAbbr(c.Type.String()),
|
||||||
SubType: treenode.SubTypeAbbr(c),
|
SubType: treenode.SubTypeAbbr(c),
|
||||||
|
Content: block.Content,
|
||||||
|
Markdown: block.Markdown,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -678,10 +683,13 @@ func GetChildBlocks(id string) (ret []*ChildBlock) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block := sql.BuildBlockFromNode(c, tree)
|
||||||
ret = append(ret, &ChildBlock{
|
ret = append(ret, &ChildBlock{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: treenode.TypeAbbr(c.Type.String()),
|
Type: treenode.TypeAbbr(c.Type.String()),
|
||||||
SubType: treenode.SubTypeAbbr(c),
|
SubType: treenode.SubTypeAbbr(c),
|
||||||
|
Content: block.Content,
|
||||||
|
Markdown: block.Markdown,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -707,10 +715,13 @@ func GetTailChildBlocks(id string, n int) (ret []*ChildBlock) {
|
||||||
children := treenode.HeadingChildren(node)
|
children := treenode.HeadingChildren(node)
|
||||||
for i := len(children) - 1; 0 <= i; i-- {
|
for i := len(children) - 1; 0 <= i; i-- {
|
||||||
c := children[i]
|
c := children[i]
|
||||||
|
block := sql.BuildBlockFromNode(c, tree)
|
||||||
ret = append(ret, &ChildBlock{
|
ret = append(ret, &ChildBlock{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: treenode.TypeAbbr(c.Type.String()),
|
Type: treenode.TypeAbbr(c.Type.String()),
|
||||||
SubType: treenode.SubTypeAbbr(c),
|
SubType: treenode.SubTypeAbbr(c),
|
||||||
|
Content: block.Content,
|
||||||
|
Markdown: block.Markdown,
|
||||||
})
|
})
|
||||||
if n == len(ret) {
|
if n == len(ret) {
|
||||||
return
|
return
|
||||||
|
@ -728,10 +739,13 @@ func GetTailChildBlocks(id string, n int) (ret []*ChildBlock) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block := sql.BuildBlockFromNode(c, tree)
|
||||||
ret = append(ret, &ChildBlock{
|
ret = append(ret, &ChildBlock{
|
||||||
ID: c.ID,
|
ID: c.ID,
|
||||||
Type: treenode.TypeAbbr(c.Type.String()),
|
Type: treenode.TypeAbbr(c.Type.String()),
|
||||||
SubType: treenode.SubTypeAbbr(c),
|
SubType: treenode.SubTypeAbbr(c),
|
||||||
|
Content: block.Content,
|
||||||
|
Markdown: block.Markdown,
|
||||||
})
|
})
|
||||||
|
|
||||||
if n == len(ret) {
|
if n == len(ret) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue