🎨 块引缺失锚文本情况下自动补全 https://github.com/siyuan-note/siyuan/issues/6087

This commit is contained in:
Liang Ding 2022-10-08 10:26:55 +08:00
parent 166fdc7e1b
commit d97254f212
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -196,7 +196,7 @@ func renderTemplate(p, id string) (string, error) {
return "", errors.New(msg)
}
var nodesNeedAppendChild []*ast.Node
var nodesNeedAppendChild, unlinks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
@ -213,11 +213,35 @@ func renderTemplate(p, id string) (string, error) {
(ast.NodeBlockquote == n.Type && nil != n.FirstChild && nil != n.FirstChild.Next && ast.NodeKramdownBlockIAL == n.FirstChild.Next.Type) {
nodesNeedAppendChild = append(nodesNeedAppendChild, n)
}
// 块引缺失锚文本情况下自动补全 https://github.com/siyuan-note/siyuan/issues/6087
if n.IsTextMarkType("block-ref") {
if refText := n.Text(); "" == refText {
refText = sql.GetRefText(n.TextMarkBlockRefID)
if "" != refText {
treenode.SetDynamicBlockRefText(n, refText)
} else {
unlinks = append(unlinks, n)
}
}
} else if ast.NodeBlockRef == n.Type {
if idNode := n.ChildByType(ast.NodeBlockRefID); nil != idNode {
refText := sql.GetRefText(idNode.TokensStr())
if "" != refText {
treenode.SetDynamicBlockRefText(n, refText)
} else {
unlinks = append(unlinks, n)
}
}
}
return ast.WalkContinue
})
for _, n := range nodesNeedAppendChild {
n.AppendChild(parse.NewParagraph())
}
for _, n := range unlinks {
n.Unlink()
}
// 折叠标题导出为模板后使用会出现内容重复 https://github.com/siyuan-note/siyuan/issues/4488
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {