Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: 渲染虚拟引用和搜索高亮导致 Markdown 标记符重复解析 Fix https://github.com/siyuan-note/siyuan/issues/6352

Liang Ding2f54fc0b8ad4
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index efafd41cdd..5b1b6d38f8 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -28,6 +28,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
+ "github.com/88250/lute/lex"
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/sets/hashset"
"github.com/facette/natsort"
@@ -308,6 +309,7 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
n.Tokens = gulu.Str.ToBytes(newText)
if bytes.Contains(n.Tokens, []byte("search-mark")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"+searchMarkSpanStart), []byte("\\\\"+searchMarkSpanEnd))
+ n.Tokens = lex.EscapeMarkers(n.Tokens)
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
var children []*ast.Node
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
diff --git a/kernel/model/file.go b/kernel/model/file.go
index f30bd15a2b..da6bd4c202 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -34,6 +34,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
+ "github.com/88250/lute/lex"
"github.com/88250/lute/parse"
util2 "github.com/88250/lute/util"
"github.com/dustin/go-humanize"
@@ -665,6 +666,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
n.Tokens = gulu.Str.ToBytes(text)
if bytes.Contains(n.Tokens, []byte("search-mark")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"+searchMarkSpanStart), []byte("\\\\"+searchMarkSpanEnd))
+ n.Tokens = lex.EscapeMarkers(n.Tokens)
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
var children []*ast.Node
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
@@ -704,6 +706,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
}
n.Tokens = []byte(newContent)
+ n.Tokens = lex.EscapeMarkers(n.Tokens)
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
var children []*ast.Node
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 854c4ea695..7a7945fc90 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -32,6 +32,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
+ "github.com/88250/lute/lex"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/siyuan-note/filelock"
@@ -186,6 +187,7 @@ func GetDocHistoryContent(historyPath, keyword string) (id, rootID, content stri
n.Tokens = gulu.Str.ToBytes(text)
if bytes.Contains(n.Tokens, []byte("search-mark")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"+searchMarkSpanStart), []byte("\\\\"+searchMarkSpanStart))
+ n.Tokens = lex.EscapeMarkers(n.Tokens)
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)
var children []*ast.Node
for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next {