Skip to content

Commit

Permalink
🎨 Improve handling of copy block ref when including images siyuan-not…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 30, 2023
1 parent 82bed84 commit 121d33e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kernel/api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ func getTreeStat(c *gin.Context) {
ret.Data = model.StatTree(id)
}

func getDOMText(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

arg, ok := util.JsonArg(c, ret)
if !ok {
return
}

dom := arg["dom"].(string)
ret.Data = model.GetDOMText(dom)
}

func getRefText(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
Expand Down
1 change: 1 addition & 0 deletions kernel/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/getRefIDsByFileAnnotationID", model.CheckAuth, getRefIDsByFileAnnotationID)
ginServer.Handle("POST", "/api/block/getBlockDefIDsByRefText", model.CheckAuth, getBlockDefIDsByRefText)
ginServer.Handle("POST", "/api/block/getRefText", model.CheckAuth, getRefText)
ginServer.Handle("POST", "/api/block/getDOMText", model.CheckAuth, getDOMText)
ginServer.Handle("POST", "/api/block/getTreeStat", model.CheckAuth, getTreeStat)
ginServer.Handle("POST", "/api/block/getBlocksWordCount", model.CheckAuth, getBlocksWordCount)
ginServer.Handle("POST", "/api/block/getContentWordCount", model.CheckAuth, getContentWordCount)
Expand Down
7 changes: 7 additions & 0 deletions kernel/model/blockinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ func GetBlockRefText(id string) string {
return getNodeRefText(node)
}

func GetDOMText(dom string) (ret string) {
luteEngine := NewLute()
tree := luteEngine.BlockDOM2Tree(dom)
ret = renderBlockText(tree.Root, nil)
return
}

func getBlockRefText(id string, tree *parse.Tree) (ret string) {
node := treenode.GetNodeInTree(tree, id)
if nil == node {
Expand Down

0 comments on commit 121d33e

Please sign in to comment.