mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-21 07:46:09 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
037c6451d7
6 changed files with 207 additions and 60 deletions
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -81,7 +81,18 @@ func findReplace(c *gin.Context) {
|
|||
for _, id := range idsArg {
|
||||
ids = append(ids, id.(string))
|
||||
}
|
||||
err := model.FindReplace(k, r, ids, paths, boxes, types, method, orderBy, groupBy)
|
||||
|
||||
replaceTypes := map[string]bool{}
|
||||
// text, img-text, img-title, img-src, a-text, a-title, a-href, code, em, strong, inline-math, inline-memo, kbd, mark, s, sub, sup, tag, u
|
||||
// doc-title, code-block, math-block, html-block
|
||||
if nil != arg["replaceTypes"] {
|
||||
replaceTypesArg := arg["replaceTypes"].(map[string]interface{})
|
||||
for t, b := range replaceTypesArg {
|
||||
replaceTypes[t] = b.(bool)
|
||||
}
|
||||
}
|
||||
|
||||
err := model.FindReplace(k, r, replaceTypes, ids, paths, boxes, types, method, orderBy, groupBy)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||
github.com/88250/gulu v1.2.3-0.20231209020950-b7b6994e395c
|
||||
github.com/88250/lute v1.7.6-0.20231215134055-5ee5630d67d5
|
||||
github.com/88250/lute v1.7.6-0.20231215140815-899eaf6868e4
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
||||
|
|
|
|||
|
|
@ -10,10 +10,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
|
|||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20231209020950-b7b6994e395c h1:Fas3hxqP33xA9KKDV50jUmppiiOukk5bdV00Hk5VSSk=
|
||||
github.com/88250/gulu v1.2.3-0.20231209020950-b7b6994e395c/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
|
||||
github.com/88250/lute v1.7.6-0.20231214125633-e04c1acd8cc9 h1:vw9GrsTRATXRDQOYLmxF+zgRlXs9szhxedMNtswg9zA=
|
||||
github.com/88250/lute v1.7.6-0.20231214125633-e04c1acd8cc9/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20231215134055-5ee5630d67d5 h1:ENdlCGQf0i+jeIztBrWWyEPONSo5mN4x4xss7dUy2Hk=
|
||||
github.com/88250/lute v1.7.6-0.20231215134055-5ee5630d67d5/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20231215140815-899eaf6868e4 h1:/M4Au0UFIgYPxJ9RGmqonYF+9E+v2E20POUNIzW587s=
|
||||
github.com/88250/lute v1.7.6-0.20231215140815-899eaf6868e4/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ func prependNotebookNameInHPath(blocks []*Block) {
|
|||
}
|
||||
}
|
||||
|
||||
func FindReplace(keyword, replacement string, ids []string, paths, boxes []string, types map[string]bool, method, orderBy, groupBy int) (err error) {
|
||||
func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids []string, paths, boxes []string, types map[string]bool, method, orderBy, groupBy int) (err error) {
|
||||
// method:0:文本,1:查询语法,2:SQL,3:正则表达式
|
||||
if 1 == method || 2 == method {
|
||||
err = errors.New(Conf.Language(132))
|
||||
|
|
@ -353,6 +353,10 @@ func FindReplace(keyword, replacement string, ids []string, paths, boxes []strin
|
|||
}
|
||||
|
||||
if ast.NodeDocument == node.Type {
|
||||
if !replaceTypes["doc-title"] {
|
||||
continue
|
||||
}
|
||||
|
||||
title := node.IALAttr("title")
|
||||
if 0 == method {
|
||||
if strings.Contains(title, keyword) {
|
||||
|
|
@ -372,18 +376,54 @@ func FindReplace(keyword, replacement string, ids []string, paths, boxes []strin
|
|||
}
|
||||
|
||||
switch n.Type {
|
||||
case ast.NodeText, ast.NodeLinkDest, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeCodeBlockCode, ast.NodeMathBlockContent, ast.NodeHTMLBlock:
|
||||
if 0 == method {
|
||||
if bytes.Contains(n.Tokens, []byte(keyword)) {
|
||||
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(string(n.Tokens)) {
|
||||
n.Tokens = []byte(r.ReplaceAllString(string(n.Tokens), replacement))
|
||||
}
|
||||
case ast.NodeText:
|
||||
if !replaceTypes["text"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeLinkDest:
|
||||
if !replaceTypes["img-src"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeLinkText:
|
||||
if !replaceTypes["img-text"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeLinkTitle:
|
||||
if !replaceTypes["img-title"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeCodeBlockCode:
|
||||
if !replaceTypes["code-block"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeMathBlockContent:
|
||||
if !replaceTypes["math-block"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeHTMLBlock:
|
||||
if !replaceTypes["html-block"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTokens(n, method, keyword, replacement, r)
|
||||
case ast.NodeTextMark:
|
||||
if n.IsTextMarkType("code") {
|
||||
if !replaceTypes["code"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkTextContent, escapedKey) {
|
||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement)
|
||||
|
|
@ -393,51 +433,124 @@ func FindReplace(keyword, replacement string, ids []string, paths, boxes []strin
|
|||
n.TextMarkTextContent = escapedR.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if n.IsTextMarkType("a") {
|
||||
if replaceTypes["a-text"] {
|
||||
if 0 == method {
|
||||
if bytes.Contains(n.Tokens, []byte(keyword)) {
|
||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if replaceTypes["a-title"] {
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkATitle, keyword) {
|
||||
n.TextMarkATitle = strings.ReplaceAll(n.TextMarkATitle, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkATitle) {
|
||||
n.TextMarkATitle = r.ReplaceAllString(n.TextMarkATitle, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if replaceTypes["a-href"] {
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkAHref, keyword) {
|
||||
n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkAHref) {
|
||||
n.TextMarkAHref = r.ReplaceAllString(n.TextMarkAHref, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if n.IsTextMarkType("em") {
|
||||
if !replaceTypes["em"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("strong") {
|
||||
if !replaceTypes["strong"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("kbd") {
|
||||
if !replaceTypes["kbd"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("mark") {
|
||||
if !replaceTypes["mark"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("s") {
|
||||
if !replaceTypes["s"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("sub") {
|
||||
if !replaceTypes["sub"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("sup") {
|
||||
if !replaceTypes["sup"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("tag") {
|
||||
if !replaceTypes["tag"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("u") {
|
||||
if !replaceTypes["u"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
replaceNodeTextMarkTextContent(n, method, keyword, replacement, r)
|
||||
} else if n.IsTextMarkType("inline-math") {
|
||||
if !replaceTypes["inline-math"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if 0 == method {
|
||||
if bytes.Contains(n.Tokens, []byte(keyword)) {
|
||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
||||
if strings.Contains(n.TextMarkInlineMathContent, keyword) {
|
||||
n.TextMarkInlineMathContent = strings.ReplaceAll(n.TextMarkInlineMathContent, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkTextContent, keyword) {
|
||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
||||
}
|
||||
if strings.Contains(n.TextMarkInlineMathContent, keyword) {
|
||||
n.TextMarkInlineMathContent = strings.ReplaceAll(n.TextMarkInlineMathContent, keyword, replacement)
|
||||
}
|
||||
if strings.Contains(n.TextMarkInlineMemoContent, keyword) {
|
||||
n.TextMarkInlineMemoContent = strings.ReplaceAll(n.TextMarkInlineMemoContent, keyword, replacement)
|
||||
}
|
||||
if strings.Contains(n.TextMarkATitle, keyword) {
|
||||
n.TextMarkATitle = strings.ReplaceAll(n.TextMarkATitle, keyword, replacement)
|
||||
}
|
||||
if strings.Contains(n.TextMarkAHref, keyword) {
|
||||
n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r {
|
||||
if r.MatchString(n.TextMarkTextContent) {
|
||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||
}
|
||||
if r.MatchString(n.TextMarkInlineMathContent) {
|
||||
if nil != r && r.MatchString(n.TextMarkInlineMathContent) {
|
||||
n.TextMarkInlineMathContent = r.ReplaceAllString(n.TextMarkInlineMathContent, replacement)
|
||||
}
|
||||
if r.MatchString(n.TextMarkInlineMemoContent) {
|
||||
}
|
||||
} else if n.IsTextMarkType("inline-memo") {
|
||||
if !replaceTypes["inline-memo"] {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkInlineMemoContent, keyword) {
|
||||
n.TextMarkInlineMemoContent = strings.ReplaceAll(n.TextMarkInlineMemoContent, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkInlineMemoContent) {
|
||||
n.TextMarkInlineMemoContent = r.ReplaceAllString(n.TextMarkInlineMemoContent, replacement)
|
||||
}
|
||||
if r.MatchString(n.TextMarkATitle) {
|
||||
n.TextMarkATitle = r.ReplaceAllString(n.TextMarkATitle, replacement)
|
||||
}
|
||||
if r.MatchString(n.TextMarkAHref) {
|
||||
n.TextMarkAHref = r.ReplaceAllString(n.TextMarkAHref, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -469,6 +582,30 @@ func FindReplace(keyword, replacement string, ids []string, paths, boxes []strin
|
|||
return
|
||||
}
|
||||
|
||||
func replaceNodeTextMarkTextContent(n *ast.Node, method int, keyword string, replacement string, r *regexp.Regexp) {
|
||||
if 0 == method {
|
||||
if strings.Contains(n.TextMarkTextContent, keyword) {
|
||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func replaceNodeTokens(n *ast.Node, method int, keyword string, replacement string, r *regexp.Regexp) {
|
||||
if 0 == method {
|
||||
if bytes.Contains(n.Tokens, []byte(keyword)) {
|
||||
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))
|
||||
}
|
||||
} else if 3 == method {
|
||||
if nil != r && r.MatchString(string(n.Tokens)) {
|
||||
n.Tokens = []byte(r.ReplaceAllString(string(n.Tokens), replacement))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FullTextSearchBlock 搜索内容块。
|
||||
//
|
||||
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||
|
|
|
|||
|
|
@ -419,11 +419,12 @@ var typeAbbrMap = map[string]string{
|
|||
"NodeThematicBreak": "tb",
|
||||
"NodeVideo": "video",
|
||||
"NodeAudio": "audio",
|
||||
"NodeText": "text",
|
||||
"NodeImage": "img",
|
||||
"NodeLinkText": "link_text",
|
||||
"NodeLinkDest": "link_dest",
|
||||
"NodeTextMark": "textmark",
|
||||
// 行级元素
|
||||
"NodeText": "text",
|
||||
"NodeImage": "img",
|
||||
"NodeLinkText": "link_text",
|
||||
"NodeLinkDest": "link_dest",
|
||||
"NodeTextMark": "textmark",
|
||||
}
|
||||
|
||||
var abbrTypeMap = map[string]string{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue