🎨 虚拟引用关键字排除列表 支持正则表达式 Fix https://github.com/siyuan-note/siyuan/issues/6696

This commit is contained in:
Liang Ding 2022-11-24 12:15:08 +08:00
parent eb3098bfe9
commit c04e10914b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 25 additions and 2 deletions

View file

@ -17,6 +17,7 @@
package model
import (
"regexp"
"sort"
"strings"
@ -97,13 +98,29 @@ func getVirtualRefKeywords(docName string) (ret []string) {
if "" != strings.TrimSpace(Conf.Editor.VirtualBlockRefExclude) {
exclude := strings.ReplaceAll(Conf.Editor.VirtualBlockRefExclude, "\\,", "__comma@sep__")
excludes := strings.Split(exclude, ",")
var tmp []string
var tmp, regexps []string
for _, e := range excludes {
e = strings.ReplaceAll(e, "__comma@sep__", ",")
tmp = append(tmp, e)
if strings.HasPrefix(e, "/") && strings.HasSuffix(e, "/") {
regexps = append(regexps, e[1:len(e)-1])
} else {
tmp = append(tmp, e)
}
}
excludes = tmp
ret = gulu.Str.ExcludeElem(ret, excludes)
if 0 < len(regexps) {
tmp = nil
for _, re := range regexps {
for _, str := range ret {
if ok, regErr := regexp.MatchString(re, str); !ok && nil == regErr {
tmp = append(tmp, str)
break
}
}
}
ret = tmp
}
}
// 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537