mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve search highlighting https://github.com/siyuan-note/siyuan/issues/13343
This commit is contained in:
parent
4b3f95e4bf
commit
c1fd34f57b
6 changed files with 32 additions and 14 deletions
|
|
@ -62,7 +62,7 @@ type Backlink struct {
|
|||
node *ast.Node // 仅用于按文档内容顺序排序
|
||||
}
|
||||
|
||||
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (ret []*Backlink) {
|
||||
func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink) {
|
||||
var keywords []string
|
||||
keyword = strings.TrimSpace(keyword)
|
||||
if "" != keyword {
|
||||
|
|
@ -102,7 +102,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
|
|||
var refTree *parse.Tree
|
||||
trees := filesys.LoadTrees(mentionBlockIDs)
|
||||
for id, tree := range trees {
|
||||
backlink := buildBacklink(id, tree, mentionKeywords, luteEngine)
|
||||
backlink := buildBacklink(id, tree, mentionKeywords, highlight, luteEngine)
|
||||
if nil != backlink {
|
||||
ret = append(ret, backlink)
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
|
|||
return
|
||||
}
|
||||
|
||||
func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret []*Backlink) {
|
||||
func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight bool) (ret []*Backlink) {
|
||||
var keywords []string
|
||||
keyword = strings.TrimSpace(keyword)
|
||||
if "" != keyword {
|
||||
|
|
@ -150,7 +150,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
|
|||
|
||||
luteEngine := util.NewLute()
|
||||
for _, linkRef := range linkRefs {
|
||||
backlink := buildBacklink(linkRef.ID, refTree, keywords, luteEngine)
|
||||
backlink := buildBacklink(linkRef.ID, refTree, keywords, highlight, luteEngine)
|
||||
if nil != backlink {
|
||||
ret = append(ret, backlink)
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ func sortBacklinks(backlinks []*Backlink, tree *parse.Tree) {
|
|||
})
|
||||
}
|
||||
|
||||
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, luteEngine *lute.Lute) (ret *Backlink) {
|
||||
func buildBacklink(refID string, refTree *parse.Tree, keywords []string, highlight bool, luteEngine *lute.Lute) (ret *Backlink) {
|
||||
n := treenode.GetNodeInTree(refTree, refID)
|
||||
if nil == n {
|
||||
return
|
||||
|
|
@ -199,7 +199,7 @@ func buildBacklink(refID string, refTree *parse.Tree, keywords []string, luteEng
|
|||
|
||||
renderNodes, expand := getBacklinkRenderNodes(n)
|
||||
|
||||
if 0 < len(keywords) {
|
||||
if highlight && 0 < len(keywords) {
|
||||
for _, renderNode := range renderNodes {
|
||||
var unlinks []*ast.Node
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue