From 07ae572d8d2d8cf8e8d19e94b30a7a809af0bda8 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 8 Dec 2022 14:49:24 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20Fix=20https://github.com/siyuan-n?= =?UTF-8?q?ote/siyuan/issues/6816?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/tag.go | 27 ++++----------------------- kernel/sql/database.go | 6 +++--- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/kernel/model/tag.go b/kernel/model/tag.go index 0af770f64..13d387f3a 100644 --- a/kernel/model/tag.go +++ b/kernel/model/tag.go @@ -17,10 +17,8 @@ package model import ( - "bytes" "errors" "fmt" - "github.com/siyuan-note/logging" "sort" "strings" @@ -29,6 +27,7 @@ import ( "github.com/88250/lute/html" "github.com/emirpasic/gods/sets/hashset" "github.com/facette/natsort" + "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" @@ -83,16 +82,7 @@ func RemoveTag(label string) (err error) { continue } - nodeTags := node.ChildrenByType(ast.NodeTag) - for _, nodeTag := range nodeTags { - nodeLabels := nodeTag.ChildrenByType(ast.NodeText) - for _, nodeLabel := range nodeLabels { - if bytes.Equal(nodeLabel.Tokens, []byte(label)) { - unlinks = append(unlinks, nodeTag) - } - } - } - nodeTags = node.ChildrenByType(ast.NodeTextMark) + nodeTags := node.ChildrenByType(ast.NodeTextMark) for _, nodeTag := range nodeTags { if nodeTag.IsTextMarkType("tag") { if label == nodeTag.TextMarkTextContent { @@ -181,19 +171,10 @@ func RenameTag(oldLabel, newLabel string) (err error) { continue } - nodeTags := node.ChildrenByType(ast.NodeTag) - for _, nodeTag := range nodeTags { - nodeLabels := nodeTag.ChildrenByType(ast.NodeText) - for _, nodeLabel := range nodeLabels { - if bytes.Equal(nodeLabel.Tokens, []byte(oldLabel)) { - nodeLabel.Tokens = bytes.ReplaceAll(nodeLabel.Tokens, []byte(oldLabel), []byte(newLabel)) - } - } - } - nodeTags = node.ChildrenByType(ast.NodeTextMark) + nodeTags := node.ChildrenByType(ast.NodeTextMark) for _, nodeTag := range nodeTags { if nodeTag.IsTextMarkType("tag") { - if oldLabel == nodeTag.TextMarkTextContent { + if strings.HasPrefix(nodeTag.TextMarkTextContent, oldLabel+"/") || nodeTag.TextMarkTextContent == oldLabel { nodeTag.TextMarkTextContent = strings.ReplaceAll(nodeTag.TextMarkTextContent, oldLabel, newLabel) } } diff --git a/kernel/sql/database.go b/kernel/sql/database.go index a5f748ab1..8464396b2 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -1232,11 +1232,11 @@ func nSort(n *ast.Node) int { return 20 case ast.NodeSuperBlock: return 30 - // 以下为行级元素 case ast.NodeText, ast.NodeTextMark: + if n.IsTextMarkType("tag") { + return 205 + } return 200 - case ast.NodeTag: - return 205 } return 100 }