diff --git a/kernel/api/block.go b/kernel/api/block.go index 46986a10c6c..90e79b50ae4 100644 --- a/kernel/api/block.go +++ b/kernel/api/block.go @@ -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) diff --git a/kernel/api/router.go b/kernel/api/router.go index 4a27bdd7177..fcd7fffb241 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -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) diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go index acebebdb9f1..e2aa800b0e8 100644 --- a/kernel/model/blockinfo.go +++ b/kernel/model/blockinfo.go @@ -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 {