mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Repeated references to the same block within a block only count as one reference Fix https://github.com/siyuan-note/siyuan/issues/9670
This commit is contained in:
parent
cbc005119a
commit
6bb89ed2e5
2 changed files with 23 additions and 4 deletions
|
|
@ -73,8 +73,8 @@ func removeDuplicateDatabaseRefs() {
|
||||||
refreshRefsByDefID(rootID)
|
refreshRefsByDefID(rootID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 < len(duplicatedRootIDs) {
|
for _, rootID := range duplicatedRootIDs {
|
||||||
logging.LogWarnf("exist more than one ref duplicated [%d], reindex it", len(duplicatedRootIDs))
|
logging.LogWarnf("exist more than one ref duplicated [%s], reindex it", rootID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,9 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno
|
||||||
|
|
||||||
if treenode.IsBlockRef(n) {
|
if treenode.IsBlockRef(n) {
|
||||||
ref := buildRef(tree, n)
|
ref := buildRef(tree, n)
|
||||||
refs = append(refs, ref)
|
if !isRepeatedRef(refs, ref) {
|
||||||
|
refs = append(refs, ref)
|
||||||
|
}
|
||||||
} else if treenode.IsFileAnnotationRef(n) {
|
} else if treenode.IsFileAnnotationRef(n) {
|
||||||
pathID := n.TextMarkFileAnnotationRefID
|
pathID := n.TextMarkFileAnnotationRefID
|
||||||
idx := strings.LastIndex(pathID, "/")
|
idx := strings.LastIndex(pathID, "/")
|
||||||
|
|
@ -385,15 +387,32 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno
|
||||||
fileAnnotationRefs = append(fileAnnotationRefs, ref)
|
fileAnnotationRefs = append(fileAnnotationRefs, ref)
|
||||||
} else if treenode.IsEmbedBlockRef(n) {
|
} else if treenode.IsEmbedBlockRef(n) {
|
||||||
ref := buildEmbedRef(tree, n)
|
ref := buildEmbedRef(tree, n)
|
||||||
refs = append(refs, ref)
|
if !isRepeatedRef(refs, ref) {
|
||||||
|
refs = append(refs, ref)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isRepeatedRef(refs []*Ref, ref *Ref) bool {
|
||||||
|
// Repeated references to the same block within a block only count as one reference https://github.com/siyuan-note/siyuan/issues/9670
|
||||||
|
for _, r := range refs {
|
||||||
|
if r.DefBlockID == ref.DefBlockID && r.BlockID == ref.BlockID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func buildRef(tree *parse.Tree, refNode *ast.Node) *Ref {
|
func buildRef(tree *parse.Tree, refNode *ast.Node) *Ref {
|
||||||
|
// 多个类型可能会导致渲染的 Markdown 不正确,所以这里只保留 block-ref 类型
|
||||||
|
tmpTyp := refNode.TextMarkType
|
||||||
|
refNode.TextMarkType = "block-ref"
|
||||||
markdown := treenode.ExportNodeStdMd(refNode, luteEngine)
|
markdown := treenode.ExportNodeStdMd(refNode, luteEngine)
|
||||||
|
refNode.TextMarkType = tmpTyp
|
||||||
|
|
||||||
defBlockID, text, _ := treenode.GetBlockRef(refNode)
|
defBlockID, text, _ := treenode.GetBlockRef(refNode)
|
||||||
var defBlockParentID, defBlockRootID, defBlockPath string
|
var defBlockParentID, defBlockRootID, defBlockPath string
|
||||||
defBlock := treenode.GetBlockTree(defBlockID)
|
defBlock := treenode.GetBlockTree(defBlockID)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue