mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 23:38:49 +01:00
🎨 Search preview supports HTML tags in inline code content https://github.com/siyuan-note/siyuan/issues/11418
This commit is contained in:
parent
67a4613d31
commit
4624b62e4d
2 changed files with 14 additions and 2 deletions
|
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/lex"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/vitess-sqlparser/sqlparser"
|
||||
|
|
@ -1538,8 +1539,8 @@ func stringQuery(query string) string {
|
|||
|
||||
// markReplaceSpan 用于处理搜索高亮。
|
||||
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markSpanDataType string, luteEngine *lute.Lute) bool {
|
||||
text := n.Content()
|
||||
if ast.NodeText == n.Type {
|
||||
text := n.Content()
|
||||
escapedText := util.EscapeHTML(text)
|
||||
escapedKeywords := make([]string, len(keywords))
|
||||
for i, keyword := range keywords {
|
||||
|
|
@ -1569,6 +1570,17 @@ func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markS
|
|||
return false
|
||||
}
|
||||
|
||||
var text string
|
||||
if n.IsTextMarkType("code") {
|
||||
// code 在前面的 n.
|
||||
for i, k := range keywords {
|
||||
keywords[i] = html.EscapeString(k)
|
||||
}
|
||||
text = n.TextMarkTextContent
|
||||
} else {
|
||||
text = n.Content()
|
||||
}
|
||||
|
||||
startTag := search.GetMarkSpanStart(markSpanDataType)
|
||||
text = search.EncloseHighlighting(text, keywords, startTag, search.GetMarkSpanEnd(), Conf.Search.CaseSensitive, false)
|
||||
if strings.Contains(text, search.MarkDataType) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue