Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: 标签系统异常 https://github.com/siyuan-note/insider/issues/1064

Liang Dingaaedbb2a7f5a
diff --git a/kernel/model/export.go b/kernel/model/export.go
index c75461476c..20c2da9367 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1096,6 +1096,12 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros bool) (ret *parse.T
status := processFileAnnotationRef(refID, n)
unlinks = append(unlinks, n)
return status
+ } else if n.IsTextMarkType("tag") {
+ if !wysiwyg {
+ n.Type = ast.NodeText
+ n.Tokens = []byte(Conf.Export.TagOpenMarker + n.TextMarkTextContent + Conf.Export.TagCloseMarker)
+ return ast.WalkContinue
+ }
}
case ast.NodeFileAnnotationRef:
refIDNode := n.ChildByType(ast.NodeFileAnnotationRefID)
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 763fef64de..7cf67eeb03 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -399,7 +399,7 @@ func query2Stmt(queryStr string) (ret string) {
if !entering {
return ast.WalkContinue
}
- if ast.NodeTag == n.Type {
+ if ast.NodeTag == n.Type || (n.IsTextMarkType("tag")) {
tags = append(tags, n.Text())
}
return ast.WalkContinue
diff --git a/kernel/model/tag.go b/kernel/model/tag.go
index 47411035a0..461d505e95 100644
--- a/kernel/model/tag.go
+++ b/kernel/model/tag.go
@@ -91,6 +91,14 @@ func RemoveTag(label string) (err error) {
}
}
}
+ nodeTags = node.ChildrenByType(ast.NodeTextMark)
+ for _, nodeTag := range nodeTags {
+ if nodeTag.IsTextMarkType("tag") {
+ if label == nodeTag.TextMarkTextContent {
+ unlinks = append(unlinks, nodeTag)
+ }
+ }
+ }
}
for _, n := range unlinks {
n.Unlink()
@@ -181,6 +189,14 @@ func RenameTag(oldLabel, newLabel string) (err error) {
}
}
}
+ nodeTags = node.ChildrenByType(ast.NodeTextMark)
+ for _, nodeTag := range nodeTags {
+ if nodeTag.IsTextMarkType("tag") {
+ if oldLabel == nodeTag.TextMarkTextContent {
+ nodeTag.TextMarkTextContent = strings.ReplaceAll(nodeTag.TextMarkTextContent, oldLabel, newLabel)
+ }
+ }
+ }
}
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), tree.Root.IALAttr("title")))
if err = writeJSONQueue(tree); nil != err {
diff --git a/kernel/sql/database.go b/kernel/sql/database.go
index 9c08f6cd1f..66f21f710b 100644
--- a/kernel/sql/database.go
+++ b/kernel/sql/database.go
@@ -820,7 +820,7 @@ func tagFromNode(node *ast.Node) (ret string) {
return ast.WalkContinue
}
- if ast.NodeTag == n.Type {
+ if ast.NodeTag == n.Type || n.IsTextMarkType("tag") {
tagBuilder.WriteString("#")
tagBuilder.WriteString(n.Text())
tagBuilder.WriteString("# ")
diff --git a/kernel/sql/span.go b/kernel/sql/span.go
index 346d6f9aa5..d445209d92 100644
--- a/kernel/sql/span.go
+++ b/kernel/sql/span.go
@@ -81,7 +81,7 @@ func SelectSpansRawStmt(stmt string, limit int) (ret []*Span) {
}
func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
- stmt := "SELECT * FROM spans WHERE type = 'tag' AND content LIKE '%" + keyword + "%'"
+ stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%'"
stmt += " LIMIT " + strconv.Itoa(limit)
rows, err := query(stmt)
if nil != err {
@@ -97,7 +97,7 @@ func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
}
func QueryTagSpans(p string, limit int) (ret []*Span) {
- stmt := "SELECT * FROM spans WHERE type = 'tag'"
+ stmt := "SELECT * FROM spans WHERE type LIKE '%tag%'"
if "" != p {
stmt += " AND path = '" + p + "'"
}