🎨 嵌入块纳入引用计数和反链 https://github.com/siyuan-note/siyuan/issues/7096

This commit is contained in:
Liang Ding 2023-01-17 22:16:14 +08:00
parent 6afa767f01
commit 492aabcf22
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 117 additions and 50 deletions

View file

@ -277,7 +277,7 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno
if treenode.IsBlockRef(n) {
ref := buildRef(tree, n)
refs = append(refs, ref)
} else if ast.NodeTextMark == n.Type && n.IsTextMarkType("file-annotation-ref") {
} else if treenode.IsFileAnnotationRef(n) {
pathID := n.TextMarkFileAnnotationRefID
idx := strings.LastIndex(pathID, "/")
if -1 == idx {
@ -305,6 +305,9 @@ func refsFromTree(tree *parse.Tree) (refs []*Ref, fileAnnotationRefs []*FileAnno
Type: treenode.TypeAbbr(n.Type.String()),
}
fileAnnotationRefs = append(fileAnnotationRefs, ref)
} else if treenode.IsEmbedBlockRef(n) {
ref := buildEmbedRef(tree, n)
refs = append(refs, ref)
}
return ast.WalkContinue
})
@ -338,6 +341,43 @@ func buildRef(tree *parse.Tree, refNode *ast.Node) *Ref {
}
}
func buildEmbedRef(tree *parse.Tree, embedNode *ast.Node) *Ref {
markdown := treenode.ExportNodeStdMd(embedNode, luteEngine)
defBlockID, text := getEmbedRef(embedNode)
var defBlockParentID, defBlockRootID, defBlockPath string
defBlock := treenode.GetBlockTree(defBlockID)
if nil != defBlock {
defBlockParentID = defBlock.ParentID
defBlockRootID = defBlock.RootID
defBlockPath = defBlock.Path
}
return &Ref{
ID: ast.NewNodeID(),
DefBlockID: defBlockID,
DefBlockParentID: defBlockParentID,
DefBlockRootID: defBlockRootID,
DefBlockPath: defBlockPath,
BlockID: embedNode.ID,
RootID: tree.ID,
Box: tree.Box,
Path: tree.Path,
Content: text,
Markdown: markdown,
Type: treenode.TypeAbbr(embedNode.Type.String()),
}
}
func getEmbedRef(embedNode *ast.Node) (queryBlockID, refText string) {
queryBlockID = treenode.GetEmbedBlockRef(embedNode)
if "" == queryBlockID {
return
}
refText = getRefText(queryBlockID)
return
}
func fromTree(node *ast.Node, tree *parse.Tree) (blocks []*Block, spans []*Span, assets []*Asset, attributes []*Attribute) {
rootID := tree.Root.ID
boxID := tree.Box