diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go index 05405a6d3..5bb65de18 100644 --- a/kernel/model/virutalref.go +++ b/kernel/model/virutalref.go @@ -253,7 +253,7 @@ func parseKeywords(keywordsStr string) (keywords []string) { // 先处理转义的逗号 keywordsStr = strings.ReplaceAll(keywordsStr, "\\,", "__comma@sep__") // 再将连续或单个换行符替换为一个逗号,避免把 `\\\n` 转换为 `\,` - keywordsStr = regexp.MustCompile(`[\r\n]+`).ReplaceAllString(keywordsStr, ",") + keywordsStr = util.ReplaceNewline(keywordsStr, ",") // 按逗号分隔 for part := range strings.SplitSeq(keywordsStr, ",") { part = strings.TrimSpace(part) // 剔除前后的空白字符 diff --git a/kernel/util/rune.go b/kernel/util/rune.go index 9e58df926..6533508f0 100644 --- a/kernel/util/rune.go +++ b/kernel/util/rune.go @@ -27,6 +27,10 @@ import ( "github.com/siyuan-note/logging" ) +func ReplaceNewline(text, replaceWith string) string { + return regexp.MustCompile(`[\r\n]+`).ReplaceAllString(text, replaceWith) +} + func ContainsCJK(text string) bool { for _, r := range text { ret := unicode.Is(unicode.Han, r) || unicode.Is(unicode.Lm, r) ||