mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +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/gulu"
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
|
"github.com/88250/lute/html"
|
||||||
"github.com/88250/lute/lex"
|
"github.com/88250/lute/lex"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/88250/vitess-sqlparser/sqlparser"
|
"github.com/88250/vitess-sqlparser/sqlparser"
|
||||||
|
|
@ -1538,8 +1539,8 @@ func stringQuery(query string) string {
|
||||||
|
|
||||||
// markReplaceSpan 用于处理搜索高亮。
|
// markReplaceSpan 用于处理搜索高亮。
|
||||||
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markSpanDataType string, luteEngine *lute.Lute) bool {
|
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markSpanDataType string, luteEngine *lute.Lute) bool {
|
||||||
text := n.Content()
|
|
||||||
if ast.NodeText == n.Type {
|
if ast.NodeText == n.Type {
|
||||||
|
text := n.Content()
|
||||||
escapedText := util.EscapeHTML(text)
|
escapedText := util.EscapeHTML(text)
|
||||||
escapedKeywords := make([]string, len(keywords))
|
escapedKeywords := make([]string, len(keywords))
|
||||||
for i, keyword := range keywords {
|
for i, keyword := range keywords {
|
||||||
|
|
@ -1569,6 +1570,17 @@ func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markS
|
||||||
return false
|
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)
|
startTag := search.GetMarkSpanStart(markSpanDataType)
|
||||||
text = search.EncloseHighlighting(text, keywords, startTag, search.GetMarkSpanEnd(), Conf.Search.CaseSensitive, false)
|
text = search.EncloseHighlighting(text, keywords, startTag, search.GetMarkSpanEnd(), Conf.Search.CaseSensitive, false)
|
||||||
if strings.Contains(text, search.MarkDataType) {
|
if strings.Contains(text, search.MarkDataType) {
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
|
||||||
ret = text
|
ret = text
|
||||||
|
|
||||||
if reg, err := regexp.Compile(re); nil == err {
|
if reg, err := regexp.Compile(re); nil == err {
|
||||||
ret = reg.ReplaceAllStringFunc(text, func(s string) string { return openMark + util.EscapeHTML(s) + closeMark })
|
ret = reg.ReplaceAllStringFunc(text, func(s string) string { return openMark + s + closeMark })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索结果预览包含转义符问题 Search results preview contains escape character issue https://github.com/siyuan-note/siyuan/issues/9790
|
// 搜索结果预览包含转义符问题 Search results preview contains escape character issue https://github.com/siyuan-note/siyuan/issues/9790
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue