mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 02:04:20 +01:00
♻️ 一些字符串操作函数移到 Gulu 项目里
This commit is contained in:
parent
bb2fafccb1
commit
c03fba9ff7
8 changed files with 15 additions and 111 deletions
|
|
@ -236,7 +236,7 @@ func WriteCustomCSS(themeName string, cssMap map[string]interface{}) (err error)
|
|||
return
|
||||
}
|
||||
|
||||
cssData := util.RemoveInvisible(string(data))
|
||||
cssData := gulu.Str.RemoveInvisible(string(data))
|
||||
customStyleSheet := css.Parse(cssData)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
|
|
|
|||
|
|
@ -540,7 +540,7 @@ func GetDoc(id string, index int, keyword string, mode int, size int) (blockCoun
|
|||
var tmp []string
|
||||
for _, k := range virtualBlockRefKeywords {
|
||||
repl := "<span data-type=\"virtual-block-ref\">" + k + "</span>"
|
||||
if util.IsASCII(k) {
|
||||
if gulu.Str.IsASCII(k) {
|
||||
tmp = append(tmp, " "+k, " "+repl)
|
||||
tmp = append(tmp, " "+k+" ", " "+repl+" ")
|
||||
tmp = append(tmp, k+" ", repl+" ")
|
||||
|
|
@ -617,7 +617,7 @@ func GetDoc(id string, index int, keyword string, mode int, size int) (blockCoun
|
|||
blockKeys = append(blockKeys, alias)
|
||||
}
|
||||
if 0 < len(blockKeys) {
|
||||
keys := util.SubstringsBetween(newContent, "<span data-type=\"virtual-block-ref\">", "</span>")
|
||||
keys := gulu.Str.SubstringsBetween(newContent, "<span data-type=\"virtual-block-ref\">", "</span>")
|
||||
for _, k := range keys {
|
||||
if gulu.Str.Contains(k, blockKeys) {
|
||||
return ast.WalkContinue
|
||||
|
|
@ -1173,7 +1173,7 @@ func RenameDoc(boxID, p, title string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
title = util.RemoveInvisible(title)
|
||||
title = gulu.Str.RemoveInvisible(title)
|
||||
oldTitle := tree.Root.IALAttr("title")
|
||||
if oldTitle == title {
|
||||
return
|
||||
|
|
@ -1287,7 +1287,7 @@ func CreateDailyNote(boxID string) (p string, err error) {
|
|||
}
|
||||
|
||||
func createDoc(boxID, p, title, dom string) (err error) {
|
||||
title = util.RemoveInvisible(title)
|
||||
title = gulu.Str.RemoveInvisible(title)
|
||||
|
||||
baseName := strings.TrimSpace(path.Base(p))
|
||||
if "" == strings.TrimSuffix(baseName, ".sy") {
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ func searchFilter(types map[string]bool) string {
|
|||
}
|
||||
|
||||
func searchBySQL(stmt string, beforeLen int) (ret []*Block) {
|
||||
stmt = util.RemoveInvisible(stmt)
|
||||
stmt = gulu.Str.RemoveInvisible(stmt)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
||||
if 1 > len(ret) {
|
||||
|
|
@ -234,7 +234,7 @@ func searchBySQL(stmt string, beforeLen int) (ret []*Block) {
|
|||
}
|
||||
|
||||
func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
|
||||
keyword = util.RemoveInvisible(keyword)
|
||||
keyword = gulu.Str.RemoveInvisible(keyword)
|
||||
|
||||
if util.IsIDPattern(keyword) {
|
||||
ret = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 36)
|
||||
|
|
@ -282,7 +282,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
|
|||
}
|
||||
|
||||
func fullTextSearch(query, box, path, filter string, beforeLen int, querySyntax bool) (ret []*Block) {
|
||||
query = util.RemoveInvisible(query)
|
||||
query = gulu.Str.RemoveInvisible(query)
|
||||
if util.IsIDPattern(query) {
|
||||
ret = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen)
|
||||
return
|
||||
|
|
@ -394,7 +394,7 @@ func markSearch(text string, keyword string, beforeLen int) (marked string, scor
|
|||
return
|
||||
}
|
||||
|
||||
keywords := util.SubstringsBetween(marked, "__@mark__", "__mark@__")
|
||||
keywords := gulu.Str.SubstringsBetween(marked, "__@mark__", "__mark@__")
|
||||
keywords = util.RemoveDuplicatedElem(keywords)
|
||||
keyword = strings.Join(keywords, search.TermSep)
|
||||
marked = strings.ReplaceAll(marked, "__@mark__", "")
|
||||
|
|
|
|||
|
|
@ -1137,7 +1137,7 @@ func CreateCloudSyncDir(name string) (err error) {
|
|||
defer syncLock.Unlock()
|
||||
|
||||
name = strings.TrimSpace(name)
|
||||
name = util.RemoveInvisible(name)
|
||||
name = gulu.Str.RemoveInvisible(name)
|
||||
if !IsValidCloudDirName(name) {
|
||||
return errors.New(Conf.Language(37))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue