From d97254f2124f78d0c6a8ac629b8dab9d86e1b6f0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 8 Oct 2022 10:26:55 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=9D=97=E5=BC=95=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E9=94=9A=E6=96=87=E6=9C=AC=E6=83=85=E5=86=B5=E4=B8=8B=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A1=A5=E5=85=A8=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/6087?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/template.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/kernel/model/template.go b/kernel/model/template.go index 28d9488f5..8fa3e665b 100644 --- a/kernel/model/template.go +++ b/kernel/model/template.go @@ -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 {