♻️ 搜索结果高亮支持大部分行级元素 https://github.com/siyuan-note/siyuan/issues/6745

This commit is contained in:
Liang Ding 2022-11-29 22:42:15 +08:00
parent 32fb7e1882
commit 9a0f2e7bc3
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 35 additions and 25 deletions

View file

@ -440,12 +440,18 @@ func StatTree(id string) (ret *util.BlockStatResult) {
}
const (
searchMarkSpanStart = "<span data-type=\"search-mark\">"
searchMarkSpanEnd = "</span>"
virtualBlockRefSpanStart = "<span data-type=\"virtual-block-ref\">"
virtualBlockRefSpanEnd = "</span>"
searchMarkDataType = "search-mark"
virtualBlockRefDataType = "virtual-block-ref"
)
func getMarkSpanStart(dataType string) string {
return fmt.Sprintf("<span data-type=\"%s\">", dataType)
}
func getMarkSpanEnd() string {
return "</span>"
}
func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int) (blockCount, childBlockCount int, dom, parentID, parent2ID, rootID, typ string, eof bool, boxID, docPath string, err error) {
WaitForWritingFiles() // 写入数据时阻塞,避免获取到的数据不一致
@ -631,7 +637,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
}
}
if hitBlock {
if markReplaceSpan(n, &unlinks, string(n.Tokens), keywords, searchMarkSpanStart, searchMarkSpanEnd, luteEngine) {
if markReplaceSpan(n, &unlinks, keywords, searchMarkDataType, luteEngine) {
return ast.WalkContinue
}
}