From e1a9051d76754096f58626aa0b100a147e14abcb Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 28 Nov 2024 13:25:24 +0800 Subject: [PATCH] :art: Improve exporting block ref https://github.com/siyuan-note/siyuan/issues/13283 --- kernel/model/export.go | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index bd82bf72c..f00e9c24a 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -2148,32 +2148,27 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool, if 4 == blockRefMode { // 块引转脚注 unlinks = nil - if footnotesDefBlock := resolveFootnotesDefs(&refFootnotes, ret, currentTreeNodeIDs, blockRefTextLeft, blockRefTextRight); nil != footnotesDefBlock { + footnotesDefBlock := resolveFootnotesDefs(&refFootnotes, ret, currentTreeNodeIDs, blockRefTextLeft, blockRefTextRight) + if nil != footnotesDefBlock { // 如果是聚焦导出,可能存在没有使用的脚注定义块,在这里进行清理 // Improve focus export conversion of block refs to footnotes https://github.com/siyuan-note/siyuan/issues/10647 - //footnotesRefs := ret.Root.ChildrenByType(ast.NodeFootnotesRef) - //for _, ref := range footnotesRefs { - // ast.Walk(ref, func(n *ast.Node, entering bool) ast.WalkStatus { - // if !entering { - // return ast.WalkContinue - // } - // - // if treenode.IsBlockRef(n) { - // refIDsInfnDefs[n.TextMarkBlockRefID] = true - // } - // return ast.WalkContinue - // }) - //} - // - //for footnotesDef := footnotesDefBlock.FirstChild; nil != footnotesDef; footnotesDef = footnotesDef.Next { - // exist := refIDsInfnDefs[footnotesDef.ID] - // if !exist { - // unlinks = append(unlinks, footnotesDef) - // } - //} - //for _, n := range unlinks { - // n.Unlink() - //} + footnotesRefs := ret.Root.ChildrenByType(ast.NodeFootnotesRef) + for footnotesDef := footnotesDefBlock.FirstChild; nil != footnotesDef; footnotesDef = footnotesDef.Next { + exist := false + for _, ref := range footnotesRefs { + if ref.FootnotesRefId == footnotesDef.FootnotesRefId { + exist = true + break + } + } + if !exist { + unlinks = append(unlinks, footnotesDef) + } + } + + for _, n := range unlinks { + n.Unlink() + } ret.Root.AppendChild(footnotesDefBlock) }