This commit is contained in:
Liang Ding 2022-12-08 14:49:24 +08:00
parent e4c3a2d9d0
commit 07ae572d8d
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 7 additions and 26 deletions

View File

@ -17,10 +17,8 @@
package model package model
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/siyuan-note/logging"
"sort" "sort"
"strings" "strings"
@ -29,6 +27,7 @@ import (
"github.com/88250/lute/html" "github.com/88250/lute/html"
"github.com/emirpasic/gods/sets/hashset" "github.com/emirpasic/gods/sets/hashset"
"github.com/facette/natsort" "github.com/facette/natsort"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/treenode"
@ -83,16 +82,7 @@ func RemoveTag(label string) (err error) {
continue continue
} }
nodeTags := node.ChildrenByType(ast.NodeTag) nodeTags := node.ChildrenByType(ast.NodeTextMark)
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)
for _, nodeTag := range nodeTags { for _, nodeTag := range nodeTags {
if nodeTag.IsTextMarkType("tag") { if nodeTag.IsTextMarkType("tag") {
if label == nodeTag.TextMarkTextContent { if label == nodeTag.TextMarkTextContent {
@ -181,19 +171,10 @@ func RenameTag(oldLabel, newLabel string) (err error) {
continue continue
} }
nodeTags := node.ChildrenByType(ast.NodeTag) nodeTags := node.ChildrenByType(ast.NodeTextMark)
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)
for _, nodeTag := range nodeTags { for _, nodeTag := range nodeTags {
if nodeTag.IsTextMarkType("tag") { 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) nodeTag.TextMarkTextContent = strings.ReplaceAll(nodeTag.TextMarkTextContent, oldLabel, newLabel)
} }
} }

View File

@ -1232,11 +1232,11 @@ func nSort(n *ast.Node) int {
return 20 return 20
case ast.NodeSuperBlock: case ast.NodeSuperBlock:
return 30 return 30
// 以下为行级元素
case ast.NodeText, ast.NodeTextMark: case ast.NodeText, ast.NodeTextMark:
if n.IsTextMarkType("tag") {
return 205
}
return 200 return 200
case ast.NodeTag:
return 205
} }
return 100 return 100
} }