🎨 Improve block ref anchor text rendering in templates https://github.com/siyuan-note/siyuan/issues/14457

This commit is contained in:
Daniel 2025-03-30 21:34:03 +08:00
parent 86106d62c0
commit 98c51a8fd0
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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