From 2f0194aca5840bbbf97d2c983e986be452e78fa8 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 11 Nov 2022 21:24:55 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=87=E6=A1=A3=E5=9D=97=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E6=A0=87=E9=A2=98=E5=9D=97=E6=97=B6=E5=B0=86?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=A0=87=E7=AD=BE=E7=A7=BB=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=9D=97=E4=B8=8B=E6=96=B9=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/6550?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/heading.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/model/heading.go b/kernel/model/heading.go index 6811051bf..06ce3ea75 100644 --- a/kernel/model/heading.go +++ b/kernel/model/heading.go @@ -156,10 +156,29 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st } srcTree.Root.RemoveIALAttr("type") + tagIAL := srcTree.Root.IALAttr("tags") + tags := strings.Split(tagIAL, ",") + srcTree.Root.RemoveIALAttr("tags") heading := &ast.Node{ID: srcTree.Root.ID, Type: ast.NodeHeading, HeadingLevel: headingLevel, KramdownIAL: srcTree.Root.KramdownIAL} heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(srcTree.Root.IALAttr("title"))}) heading.Box = targetTree.Box heading.Path = targetTree.Path + if 0 < len(tags) { + // 带标签的文档块转换为标题块时将标签移动到标题块下方 https://github.com/siyuan-note/siyuan/issues/6550 + + tagPara := parse.NewParagraph() + for i, tag := range tags { + if "" == tag { + continue + } + + tagPara.AppendChild(&ast.Node{Type: ast.NodeTextMark, TextMarkType: "tag", TextMarkTextContent: tag}) + if i < len(tags)-1 { + tagPara.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(" ")}) + } + } + srcTree.Root.PrependChild(tagPara) + } var nodes []*ast.Node if after { @@ -306,6 +325,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID, newTree.Box, newTree.Path = targetBoxID, newTargetPath newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr()) + newTree.Root.Spec = "1" if err = indexWriteJSONQueue(newTree); nil != err { return "", "", err }