🎨 Clean code

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-20 10:03:38 +08:00
parent cfcf695fb4
commit f6e9ed5b55
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -45,9 +45,6 @@ var virtualBlockRefCache, _ = ristretto.NewCache(&ristretto.Config{
BufferItems: 64,
})
// newlineRegexp 用于匹配连续或单个换行符的正则表达式
var newlineRegexp = regexp.MustCompile(`[\r\n]+`)
func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
val, ok := virtualBlockRefCache.Get(root.ID)
if !ok {
@ -256,7 +253,7 @@ func parseKeywords(keywordsStr string) (keywords []string) {
// 先处理转义的逗号
keywordsStr = strings.ReplaceAll(keywordsStr, "\\,", "__comma@sep__")
// 再将连续或单个换行符替换为一个逗号,避免把 `\\\n` 转换为 `\,`
keywordsStr = newlineRegexp.ReplaceAllString(keywordsStr, ",")
keywordsStr = regexp.MustCompile(`[\r\n]+`).ReplaceAllString(keywordsStr, ",")
// 按逗号分隔
for part := range strings.SplitSeq(keywordsStr, ",") {
part = strings.TrimSpace(part) // 剔除前后的空白字符