Selaa lähdekoodia

:art: `pdf?page` 资源文件链接会被判定为未引用资源 Fix https://github.com/siyuan-note/siyuan/issues/5649

Liang Ding 2 vuotta sitten
vanhempi
commit
103cbf8d15
4 muutettua tiedostoa jossa 30 lisäystä ja 17 poistoa
  1. 5 0
      kernel/model/assets.go
  2. 1 1
      kernel/model/file.go
  3. 19 15
      kernel/model/search.go
  4. 5 1
      kernel/search/mark.go

+ 5 - 0
kernel/model/assets.go

@@ -573,6 +573,11 @@ func UnusedAssets() (ret []string) {
 				continue
 			}
 
+			if idx := strings.Index(dest, "?"); 0 < idx {
+				// `pdf?page` 资源文件链接会被判定为未引用资源 https://github.com/siyuan-note/siyuan/issues/5649
+				dest = dest[:idx]
+			}
+
 			if "" == assetsPathMap[dest] {
 				continue
 			}

+ 1 - 1
kernel/model/file.go

@@ -629,7 +629,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
 			// 支持代码块搜索定位 https://github.com/siyuan-note/siyuan/issues/5520
 			if ast.NodeCodeBlockCode == n.Type && 0 < len(keywords) && !render.IsChartCodeBlockCode(n) {
 				text := string(n.Tokens)
-				text = search.EncloseHighlighting(text, keywords, "__@mark__", "__mark@__", Conf.Search.CaseSensitive)
+				text = search.EncloseHighlighting(text, keywords, search.SearchMarkLeft, search.SearchMarkRight, Conf.Search.CaseSensitive)
 				n.Tokens = gulu.Str.ToBytes(text)
 			}
 

+ 19 - 15
kernel/model/search.go

@@ -26,6 +26,7 @@ import (
 
 	"github.com/88250/gulu"
 	"github.com/88250/lute/ast"
+	"github.com/88250/lute/html"
 	"github.com/88250/lute/parse"
 	"github.com/jinzhu/copier"
 	"github.com/siyuan-note/logging"
@@ -268,12 +269,12 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
 	}
 
 	projections := "id, parent_id, root_id, hash, box, path, " +
-		"snippet(" + table + ", 6, '<mark>__r', '</mark>', '...', 64) AS hpath, " +
-		"snippet(" + table + ", 7, '<mark>__r', '</mark>', '...', 64) AS name, " +
-		"snippet(" + table + ", 8, '<mark>__r', '</mark>', '...', 64) AS alias, " +
-		"snippet(" + table + ", 9, '<mark>__r', '</mark>', '...', 64) AS memo, " +
+		"snippet(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS hpath, " +
+		"snippet(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS name, " +
+		"snippet(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS alias, " +
+		"snippet(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS memo, " +
 		"tag, " +
-		"snippet(" + table + ", 11, '<mark>__r', '</mark>', '...', 64) AS content, " +
+		"snippet(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS content, " +
 		"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
 	stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(" + quotedKeyword + ")' AND type IN " + Conf.Search.TypeFilter()
 	orderBy := ` order by case
@@ -345,12 +346,12 @@ func fullTextSearch(query, box, path, filter string, beforeLen int, querySyntax
 		table = "blocks_fts_case_insensitive"
 	}
 	projections := "id, parent_id, root_id, hash, box, path, " +
-		"highlight(" + table + ", 6, '__@mark__', '__mark@__') AS hpath, " +
-		"highlight(" + table + ", 7, '__@mark__', '__mark@__') AS name, " +
-		"highlight(" + table + ", 8, '__@mark__', '__mark@__') AS alias, " +
-		"highlight(" + table + ", 9, '__@mark__', '__mark@__') AS memo, " +
+		"highlight(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS hpath, " +
+		"highlight(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS name, " +
+		"highlight(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS alias, " +
+		"highlight(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS memo, " +
 		"tag, " +
-		"highlight(" + table + ", 11, '__@mark__', '__mark@__') AS content, " +
+		"highlight(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS content, " +
 		"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
 	stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(" + query + ")' AND type IN " + filter
 	if "" != box {
@@ -439,16 +440,19 @@ func markSearch(text string, keyword string, beforeLen int) (marked string, scor
 			marked = gulu.Str.SubStr(marked, maxLen) + "..."
 		}
 
-		if strings.Contains(marked, "<mark>__r") { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
-			marked = strings.ReplaceAll(marked, "<mark>__r", "<mark>")
+		marked = html.EscapeString(text)
+
+		if strings.Contains(marked, search.SearchMarkLeft) { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
+			marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "<mark>")
+			marked = strings.ReplaceAll(marked, search.SearchMarkRight, "</mark>")
 			return
 		}
 
-		keywords := gulu.Str.SubstringsBetween(marked, "__@mark__", "__mark@__")
+		keywords := gulu.Str.SubstringsBetween(marked, search.SearchMarkLeft, search.SearchMarkRight)
 		keywords = gulu.Str.RemoveDuplicatedElem(keywords)
 		keyword = strings.Join(keywords, search.TermSep)
-		marked = strings.ReplaceAll(marked, "__@mark__", "")
-		marked = strings.ReplaceAll(marked, "__mark@__", "")
+		marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "")
+		marked = strings.ReplaceAll(marked, search.SearchMarkRight, "")
 		_, marked = search.MarkText(marked, keyword, beforeLen, Conf.Search.CaseSensitive)
 		return
 	}

+ 5 - 1
kernel/search/mark.go

@@ -53,7 +53,11 @@ func MarkText(text string, keyword string, beforeLen int, caseSensitive bool) (p
 	return
 }
 
-const TermSep = "__term@sep__"
+const (
+	TermSep         = "__term@sep__"
+	SearchMarkLeft  = "__@mark__"
+	SearchMarkRight = "__mark@__"
+)
 
 func SplitKeyword(keyword string) (keywords []string) {
 	keyword = strings.TrimSpace(keyword)