mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 08:41:33 +08:00
This commit is contained in:
parent
69c18db9ed
commit
e09b37e285
@ -19,7 +19,9 @@ package model
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/88250/lute/ast"
|
||||||
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,12 +72,40 @@ func isOpenAIAPIEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getBlocksContent(ids []string) string {
|
func getBlocksContent(ids []string) string {
|
||||||
sqlBlocks := sql.GetBlocks(ids)
|
var nodes []*ast.Node
|
||||||
buf := bytes.Buffer{}
|
trees := map[string]*parse.Tree{}
|
||||||
for _, sqlBlock := range sqlBlocks {
|
for _, id := range ids {
|
||||||
buf.WriteString(sqlBlock.Content)
|
bt := treenode.GetBlockTree(id)
|
||||||
buf.WriteString("\n\n")
|
if nil == bt {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tree *parse.Tree
|
||||||
|
if tree = trees[bt.RootID]; nil == tree {
|
||||||
|
tree, _ = loadTreeByBlockID(bt.RootID)
|
||||||
|
if nil == tree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
trees[bt.RootID] = tree
|
||||||
|
}
|
||||||
|
|
||||||
|
if node := treenode.GetNodeInTree(tree, id); nil != node {
|
||||||
|
if ast.NodeDocument == node.Type {
|
||||||
|
for child := node.FirstChild; nil != child; child = child.Next {
|
||||||
|
nodes = append(nodes, child)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
for _, node := range nodes {
|
||||||
|
content := treenode.NodeStaticContent(node, nil, true)
|
||||||
|
buf.WriteString(content)
|
||||||
|
buf.WriteString("\n\n")
|
||||||
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user