mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-19 10:30:45 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
85477cc30a
@ -204,7 +204,7 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
|
|||||||
}
|
}
|
||||||
if ast.NodeText == n.Type {
|
if ast.NodeText == n.Type {
|
||||||
text := string(n.Tokens)
|
text := string(n.Tokens)
|
||||||
newText := markReplaceSpanWithSplit(text, mentionKeywords, searchMarkSpanStart, searchMarkSpanEnd)
|
newText := markReplaceSpanWithSplit(text, mentionKeywords, getMarkSpanStart(searchMarkDataType), getMarkSpanEnd())
|
||||||
if text == newText {
|
if text == newText {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
@ -627,7 +627,6 @@ func buildTreeBackmention(defSQLBlock *sql.Block, refBlocks []*Block, keyword st
|
|||||||
|
|
||||||
func searchBackmention(mentionKeywords []string, keyword string, excludeBacklinkIDs *hashset.Set, rootID string, beforeLen int) (ret []*Block) {
|
func searchBackmention(mentionKeywords []string, keyword string, excludeBacklinkIDs *hashset.Set, rootID string, beforeLen int) (ret []*Block) {
|
||||||
ret = []*Block{}
|
ret = []*Block{}
|
||||||
|
|
||||||
if 1 > len(mentionKeywords) {
|
if 1 > len(mentionKeywords) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -696,7 +695,7 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
newText := markReplaceSpanWithSplit(text, mentionKeywords, searchMarkSpanStart, searchMarkSpanEnd)
|
newText := markReplaceSpanWithSplit(text, mentionKeywords, getMarkSpanStart(searchMarkDataType), getMarkSpanEnd())
|
||||||
if text != newText {
|
if text != newText {
|
||||||
tmp = append(tmp, b)
|
tmp = append(tmp, b)
|
||||||
}
|
}
|
||||||
|
@ -440,12 +440,18 @@ func StatTree(id string) (ret *util.BlockStatResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
searchMarkSpanStart = "<span data-type=\"search-mark\">"
|
searchMarkDataType = "search-mark"
|
||||||
searchMarkSpanEnd = "</span>"
|
virtualBlockRefDataType = "virtual-block-ref"
|
||||||
virtualBlockRefSpanStart = "<span data-type=\"virtual-block-ref\">"
|
|
||||||
virtualBlockRefSpanEnd = "</span>"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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) {
|
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() // 写入数据时阻塞,避免获取到的数据不一致
|
WaitForWritingFiles() // 写入数据时阻塞,避免获取到的数据不一致
|
||||||
|
|
||||||
@ -631,7 +637,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hitBlock {
|
if hitBlock {
|
||||||
if markReplaceSpan(n, &unlinks, string(n.Tokens), keywords, searchMarkSpanStart, searchMarkSpanEnd, luteEngine) {
|
if markReplaceSpan(n, &unlinks, keywords, searchMarkDataType, luteEngine) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ func GetDocHistoryContent(historyPath, keyword string) (id, rootID, content stri
|
|||||||
|
|
||||||
if ast.NodeText == n.Type {
|
if ast.NodeText == n.Type {
|
||||||
if 0 < len(keywords) {
|
if 0 < len(keywords) {
|
||||||
if markReplaceSpan(n, &unlinks, string(n.Tokens), keywords, searchMarkSpanStart, searchMarkSpanEnd, luteEngine) {
|
if markReplaceSpan(n, &unlinks, keywords, searchMarkDataType, luteEngine) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -830,21 +830,26 @@ func stringQuery(query string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// markReplaceSpan 用于处理搜索高亮。
|
// markReplaceSpan 用于处理搜索高亮。
|
||||||
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, text string, keywords []string, replacementStart, replacementEnd string, luteEngine *lute.Lute) bool {
|
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markSpanDataType string, luteEngine *lute.Lute) bool {
|
||||||
text = search.EncloseHighlighting(text, keywords, searchMarkSpanStart, searchMarkSpanEnd, Conf.Search.CaseSensitive)
|
text := n.Content()
|
||||||
n.Tokens = gulu.Str.ToBytes(text)
|
if ast.NodeText == n.Type {
|
||||||
if bytes.Contains(n.Tokens, []byte("search-mark")) {
|
text = search.EncloseHighlighting(text, keywords, getMarkSpanStart(markSpanDataType), getMarkSpanEnd(), Conf.Search.CaseSensitive)
|
||||||
n.Tokens = lex.EscapeMarkers(n.Tokens)
|
n.Tokens = gulu.Str.ToBytes(text)
|
||||||
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
|
if bytes.Contains(n.Tokens, []byte("search-mark")) {
|
||||||
var children []*ast.Node
|
n.Tokens = lex.EscapeMarkers(n.Tokens)
|
||||||
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
|
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
|
||||||
children = append(children, c)
|
var children []*ast.Node
|
||||||
|
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
|
||||||
|
children = append(children, c)
|
||||||
|
}
|
||||||
|
for _, c := range children {
|
||||||
|
n.InsertBefore(c)
|
||||||
|
}
|
||||||
|
*unlinks = append(*unlinks, n)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
for _, c := range children {
|
} else if ast.NodeTextMark == n.Type {
|
||||||
n.InsertBefore(c)
|
// 搜索结果高亮支持大部分行级元素 https://github.com/siyuan-note/siyuan/issues/6745
|
||||||
}
|
|
||||||
*unlinks = append(*unlinks, n)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeyword
|
|||||||
}
|
}
|
||||||
|
|
||||||
content := string(n.Tokens)
|
content := string(n.Tokens)
|
||||||
newContent := markReplaceSpanWithSplit(content, virtualBlockRefKeywords, virtualBlockRefSpanStart, virtualBlockRefSpanEnd)
|
newContent := markReplaceSpanWithSplit(content, virtualBlockRefKeywords, getMarkSpanStart(virtualBlockRefDataType), getMarkSpanEnd())
|
||||||
if content != newContent {
|
if content != newContent {
|
||||||
// 虚拟引用排除命中自身块命名和别名的情况 https://github.com/siyuan-note/siyuan/issues/3185
|
// 虚拟引用排除命中自身块命名和别名的情况 https://github.com/siyuan-note/siyuan/issues/3185
|
||||||
var blockKeys []string
|
var blockKeys []string
|
||||||
@ -52,7 +52,7 @@ func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeyword
|
|||||||
blockKeys = append(blockKeys, alias)
|
blockKeys = append(blockKeys, alias)
|
||||||
}
|
}
|
||||||
if 0 < len(blockKeys) {
|
if 0 < len(blockKeys) {
|
||||||
keys := gulu.Str.SubstringsBetween(newContent, virtualBlockRefSpanStart, virtualBlockRefSpanEnd)
|
keys := gulu.Str.SubstringsBetween(newContent, getMarkSpanStart(virtualBlockRefDataType), getMarkSpanEnd())
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if gulu.Str.Contains(k, blockKeys) {
|
if gulu.Str.Contains(k, blockKeys) {
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user