Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: 查询嵌入块多层嵌套导出不完整 Fix https://github.com/siyuan-note/siyuan/issues/5558

Liang Ding478ba156cdc6
diff --git a/kernel/model/export.go b/kernel/model/export.go
index dfc55ab737..01d48ff225 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1218,6 +1218,7 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, rootID string) (footn
}
footnotesDefBlock = &ast.Node{Type: ast.NodeFootnotesDefBlock}
+ var rendered []string
for _, foot := range *refFootnotes {
t, err := loadTreeByBlockID(foot.defID)
if nil != err {
@@ -1261,9 +1262,8 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, rootID string) (footn
stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr()
stmt = html.UnescapeString(stmt)
sqlBlocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
- depth := 0
for _, b := range sqlBlocks {
- subNodes := renderBlockMarkdownR0(b.ID, &depth)
+ subNodes := renderBlockMarkdownR0(b.ID, &rendered)
for _, subNode := range subNodes {
if ast.NodeListItem == subNode.Type {
parentList := &ast.Node{Type: ast.NodeList, ListData: &ast.ListData{Typ: subNode.ListData.Typ}}
diff --git a/kernel/model/render.go b/kernel/model/render.go
index c16ff06915..78fc1f8a43 100644
--- a/kernel/model/render.go
+++ b/kernel/model/render.go
@@ -20,6 +20,7 @@ import (
"bytes"
"strings"
+ "github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
@@ -118,8 +119,8 @@ func renderBlockDOMByNodes(nodes []*ast.Node, luteEngine *lute.Lute) string {
}
func renderBlockMarkdownR(id string) string {
- depth := 0
- nodes := renderBlockMarkdownR0(id, &depth)
+ var rendered []string
+ nodes := renderBlockMarkdownR0(id, &rendered)
buf := bytes.Buffer{}
buf.Grow(4096)
luteEngine := NewLute()
@@ -131,11 +132,12 @@ func renderBlockMarkdownR(id string) string {
return buf.String()
}
-func renderBlockMarkdownR0(id string, depth *int) (ret []*ast.Node) {
- *depth++
- if 7 < *depth {
+func renderBlockMarkdownR0(id string, rendered *[]string) (ret []*ast.Node) {
+ if gulu.Str.Contains(id, *rendered) {
return
}
+ *rendered = append(*rendered, id)
+
b := treenode.GetBlockTree(id)
if nil == b {
return
@@ -175,7 +177,7 @@ func renderBlockMarkdownR0(id string, depth *int) (ret []*ast.Node) {
stmt = html.UnescapeString(stmt)
sqlBlocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
for _, sqlBlock := range sqlBlocks {
- subNodes := renderBlockMarkdownR0(sqlBlock.ID, depth)
+ subNodes := renderBlockMarkdownR0(sqlBlock.ID, rendered)
for _, subNode := range subNodes {
inserts = append(inserts, subNode)
}