Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-09-06 18:02:31 +08:00
commit fc1cbf46aa
3 changed files with 61 additions and 7 deletions

View file

@ -189,6 +189,20 @@ func getHeadingChildrenIDs(c *gin.Context) {
ret.Data = ids
}
func appendHeadingChildren(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
id := arg["id"].(string)
childrenDOM := arg["childrenDOM"].(string)
model.AppendHeadingChildren(id, childrenDOM)
}
func getHeadingChildrenDOM(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@ -199,7 +213,11 @@ func getHeadingChildrenDOM(c *gin.Context) {
}
id := arg["id"].(string)
dom := model.GetHeadingChildrenDOM(id)
removeFoldAttr := true
if nil != arg["removeFoldAttr"] {
removeFoldAttr = arg["removeFoldAttr"].(bool)
}
dom := model.GetHeadingChildrenDOM(id, removeFoldAttr)
ret.Data = dom
}

View file

@ -222,6 +222,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/getBlockRelevantIDs", model.CheckAuth, getBlockRelevantIDs)
ginServer.Handle("POST", "/api/block/getBlockTreeInfos", model.CheckAuth, getBlockTreeInfos)
ginServer.Handle("POST", "/api/block/checkBlockRef", model.CheckAuth, checkBlockRef)
ginServer.Handle("POST", "/api/block/appendHeadingChildren", model.CheckAuth, appendHeadingChildren)
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, putFile)

View file

@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"slices"
"strings"
"time"
@ -629,7 +630,35 @@ func GetHeadingChildrenIDs(id string) (ret []string) {
return
}
func GetHeadingChildrenDOM(id string) (ret string) {
func AppendHeadingChildren(id, childrenDOM string) {
tree, err := LoadTreeByBlockID(id)
if err != nil {
return
}
heading := treenode.GetNodeInTree(tree, id)
if nil == heading || ast.NodeHeading != heading.Type {
return
}
luteEngine := util.NewLute()
subTree := luteEngine.BlockDOM2Tree(childrenDOM)
var nodes []*ast.Node
for n := subTree.Root.FirstChild; nil != n; n = n.Next {
nodes = append(nodes, n)
}
slices.Reverse(nodes)
for _, n := range nodes {
heading.InsertAfter(n)
}
if err = indexWriteTreeUpsertQueue(tree); err != nil {
return
}
}
func GetHeadingChildrenDOM(id string, removeFoldAttr bool) (ret string) {
tree, err := LoadTreeByBlockID(id)
if err != nil {
return
@ -643,20 +672,26 @@ func GetHeadingChildrenDOM(id string) (ret string) {
children := treenode.HeadingChildren(heading)
nodes = append(nodes, children...)
// 取消折叠 https://github.com/siyuan-note/siyuan/issues/13232#issuecomment-2535955152
for _, child := range children {
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if removeFoldAttr {
n.RemoveIALAttr("heading-fold")
n.RemoveIALAttr("fold")
}
return ast.WalkContinue
})
child.SetIALAttr("parent-heading", id)
}
if removeFoldAttr {
heading.RemoveIALAttr("fold")
heading.RemoveIALAttr("heading-fold")
}
luteEngine := util.NewLute()
ret = renderBlockDOMByNodes(nodes, luteEngine)