Skip to content

Commit

Permalink
🎨 Improve exporting block ref #13283
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 1, 2024
1 parent 2292f1a commit 39ddd18
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2633,18 +2633,23 @@ 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
}

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
Expand Down

0 comments on commit 39ddd18

Please sign in to comment.