Skip to content

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

:art: Improve exporting block ref https://github.com/siyuan-note/siyuan/issues/13283

Daniel39ddd1861657
diff --git a/kernel/model/export.go b/kernel/model/export.go
index a40ed830a6..4d03ee864e 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -2174,7 +2174,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
if 4 == blockRefMode { // 块引转脚注
unlinks = nil
- footnotesDefBlock := resolveFootnotesDefs(&refFootnotes, ret, currentTreeNodeIDs, blockRefTextLeft, blockRefTextRight)
+ footnotesDefBlock := resolveFootnotesDefs(&refFootnotes, ret, currentTreeNodeIDs, blockRefTextLeft, blockRefTextRight, &treeCache)
if nil != footnotesDefBlock {
// 如果是聚焦导出,可能存在没有使用的脚注定义块,在这里进行清理
// Improve focus export conversion of block refs to footnotes https://github.com/siyuan-note/siyuan/issues/10647
@@ -2633,7 +2633,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
return ret
}
-func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, currentTree *parse.Tree, currentTreeNodeIDs map[string]bool, blockRefTextLeft, blockRefTextRight string) (footnotesDefBlock *ast.Node) {
+func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, currentTree *parse.Tree, currentTreeNodeIDs map[string]bool, blockRefTextLeft, blockRefTextRight string, treeCache *map[string]*parse.Tree) (footnotesDefBlock *ast.Node) {
if 1 > len(*refFootnotes) {
return nil
}
@@ -2641,10 +2641,15 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, currentTree *parse.Tr
footnotesDefBlock = &ast.Node{Type: ast.NodeFootnotesDefBlock}
var rendered []string
for _, foot := range *refFootnotes {
- t, err := LoadTreeByBlockID(foot.defID)
- if err != nil {
- continue
+ t := (*treeCache)[foot.defID]
+ if nil == t {
+ var err error
+ if t, err = LoadTreeByBlockID(foot.defID); err != nil {
+ continue
+ }
+ (*treeCache)[t.ID] = t
}
+
defNode := treenode.GetNodeInTree(t, foot.defID)
docID := util.GetTreeID(defNode.Path)
var nodes []*ast.Node