diff --git a/kernel/model/template.go b/kernel/model/template.go index 0f6596a1c..6849a3e99 100644 --- a/kernel/model/template.go +++ b/kernel/model/template.go @@ -355,7 +355,6 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e nodesNeedAppendChild = append(nodesNeedAppendChild, n) } - // 块引缺失锚文本情况下自动补全 https://github.com/siyuan-note/siyuan/issues/6087 if n.IsTextMarkType("block-ref") { if refText := n.Text(); "" == refText { refText = strings.TrimSpace(sql.GetRefText(n.TextMarkBlockRefID)) @@ -365,6 +364,17 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e unlinks = append(unlinks, n) } } + } else if ast.NodeBlockRef == n.Type { + if refText := n.Text(); "" == refText { + if refID := n.ChildByType(ast.NodeBlockRefID); nil != refID { + refText = strings.TrimSpace(sql.GetRefText(refID.TokensStr())) + if "" != refText { + treenode.SetDynamicBlockRefText(n, refText) + } else { + unlinks = append(unlinks, n) + } + } + } } else if n.IsTextMarkType("inline-math") { if n.ParentIs(ast.NodeTableCell) { // 表格中的公式中带有管道符时使用 HTML 实体替换管道符 Improve the handling of inline-math containing `|` in the table https://github.com/siyuan-note/siyuan/issues/9227 diff --git a/kernel/treenode/node.go b/kernel/treenode/node.go index dfa13f774..c7a4c7a73 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -469,6 +469,14 @@ func SetDynamicBlockRefText(blockRef *ast.Node, refText string) { return } + if ast.NodeBlockRef == blockRef.Type { + if refID := blockRef.ChildByType(ast.NodeBlockRefID); nil != refID { + refID.InsertAfter(&ast.Node{Type: ast.NodeBlockRefDynamicText, Tokens: []byte(refText)}) + refID.InsertAfter(&ast.Node{Type: ast.NodeBlockRefSpace}) + } + return + } + refText = strings.TrimSpace(refText) if "" == refText { refText = blockRef.TextMarkBlockRefID