Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-12-28 20:51:16 +08:00
commit e09114c518
12 changed files with 42 additions and 26 deletions

File diff suppressed because one or more lines are too long

View file

@ -269,6 +269,10 @@ func getRefIDs(c *gin.Context) {
return
}
if nil == arg["id"] {
arg["id"] = ""
}
id := arg["id"].(string)
refIDs, refTexts, defIDs := model.GetBlockRefIDs(id)
ret.Data = map[string][]string{

View file

@ -21,7 +21,6 @@ import (
"strings"
"github.com/88250/gulu"
"github.com/88250/lute/html"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@ -182,7 +181,7 @@ func searchRefBlock(c *gin.Context) {
ret.Data = map[string]interface{}{
"blocks": blocks,
"newDoc": newDoc,
"k": html.EscapeHTMLStr(keyword),
"k": util.EscapeHTML(keyword),
"reqId": arg["reqId"],
}
}

View file

@ -20,7 +20,6 @@ import (
"net/http"
"github.com/88250/gulu"
"github.com/88250/lute/html"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@ -40,7 +39,7 @@ func docSaveAsTemplate(c *gin.Context) {
code, err := model.DocSaveAsTemplate(id, overwrite)
if nil != err {
ret.Code = -1
ret.Msg = html.EscapeString(err.Error())
ret.Msg = util.EscapeHTML(err.Error())
return
}
ret.Code = code
@ -60,7 +59,7 @@ func renderTemplate(c *gin.Context) {
content, err := model.RenderTemplate(p, id)
if nil != err {
ret.Code = -1
ret.Msg = html.EscapeString(err.Error())
ret.Msg = util.EscapeHTML(err.Error())
return
}

View file

@ -6,7 +6,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/css v0.1.2
github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798
github.com/88250/lute v1.7.5-0.20221228082840-f51571fe01c5
github.com/88250/lute v1.7.5-0.20221228091547-322f538d4f33
github.com/88250/pdfcpu v0.3.13
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732

View file

@ -17,14 +17,12 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798 h1:sR/s/Y9wyl79ZRCUERwLPo9zqaB3KhNRodCMTJ4ozEU=
github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
github.com/88250/lute v1.7.5-0.20221218043446-d967dba6874e h1:W9QP3v4GnZZkwKln5jrg6H6WPrtReVuuqb/NtfNx+jU=
github.com/88250/lute v1.7.5-0.20221218043446-d967dba6874e/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221228064057-0c7be092096b h1:GtIZfyOZagH+2UYEkBprh+cqJhjqTkLnVhAjkI397fc=
github.com/88250/lute v1.7.5-0.20221228064057-0c7be092096b/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221228075634-633aed35b3a7 h1:NjYTH2y9xTjp4+PmZmiPajvS530iopaq2i9d19B1cJU=
github.com/88250/lute v1.7.5-0.20221228075634-633aed35b3a7/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221228082840-f51571fe01c5 h1:TAfGEgAW0OMzwNIxvhnNrpwTgmKyQDlBZI8zg1CUqK0=
github.com/88250/lute v1.7.5-0.20221228082840-f51571fe01c5/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221228084920-dff461f9283f h1:WQZK9EER7keZLK9o6fTK5k4jcTiDpcZmyMyaOv4isV4=
github.com/88250/lute v1.7.5-0.20221228084920-dff461f9283f/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221228091547-322f538d4f33 h1:2A3pQE3Av78X690Q0deDMpT31ytc7PGIt4TNDBRlD9A=
github.com/88250/lute v1.7.5-0.20221228091547-322f538d4f33/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
github.com/88250/pdfcpu v0.3.13/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -26,7 +26,6 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
"github.com/88250/lute/parse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/sql"
@ -124,6 +123,8 @@ func getNodeRefText(node *ast.Node) string {
func GetBlockRefIDs(id string) (refIDs, refTexts, defIDs []string) {
refIDs = []string{}
refTexts = []string{}
defIDs = []string{}
bt := treenode.GetBlockTree(id)
if nil == bt {
return
@ -237,9 +238,9 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPa
fc = fc.Next
}
name := html.EscapeHTMLStr(parent.IALAttr("name"))
name := util.EscapeHTML(parent.IALAttr("name"))
if ast.NodeDocument == parent.Type {
name = html.EscapeHTMLStr(path.Join(boxName, hPath))
name = util.EscapeHTML(path.Join(boxName, hPath))
} else {
if "" == name {
if ast.NodeListItem == parent.Type {

View file

@ -28,6 +28,7 @@ import (
"github.com/88250/lute/render"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
func renderOutline(node *ast.Node, luteEngine *lute.Lute) (ret string) {
@ -71,7 +72,7 @@ func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
ret = treenode.NodeStaticContent(node, excludeTypes)
ret = strings.TrimSpace(ret)
ret = strings.ReplaceAll(ret, "\n", "")
ret = html.EscapeString(ret)
ret = util.EscapeHTML(ret)
ret = strings.TrimSpace(ret)
if "" == ret {
// 复制内容为空的块作为块引用时粘贴无效 https://github.com/siyuan-note/siyuan/issues/4962

View file

@ -31,7 +31,6 @@ 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/jinzhu/copier"
@ -228,7 +227,7 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
}
case ast.NodeTextMark:
if n.IsTextMarkType("code") {
escapedKey := html.EscapeString(keyword)
escapedKey := util.EscapeHTML(keyword)
if 0 == method {
if strings.Contains(n.TextMarkTextContent, escapedKey) {
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement)
@ -692,7 +691,7 @@ func markSearch(text string, keyword string, beforeLen int) (marked string, scor
marked = text
if strings.Contains(marked, search.SearchMarkLeft) { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
marked = html.EscapeString(text)
marked = util.EscapeHTML(text)
marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "<mark>")
marked = strings.ReplaceAll(marked, search.SearchMarkRight, "</mark>")
return

View file

@ -24,7 +24,6 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
"github.com/emirpasic/gods/sets/hashset"
"github.com/facette/natsort"
"github.com/siyuan-note/logging"
@ -360,7 +359,7 @@ func buildTags(root Tags, labels []string, depth int) Tags {
}
}
if i == len(root) {
root = append(root, &Tag{Name: html.EscapeHTMLStr(labels[0]), Type: "tag", Depth: depth})
root = append(root, &Tag{Name: util.EscapeHTML(labels[0]), Type: "tag", Depth: depth})
}
depth++
root[i].tags = buildTags(root[i].tags, labels[1:], depth)

View file

@ -21,14 +21,14 @@ import (
"strings"
"unicode/utf8"
"github.com/88250/lute/html"
"github.com/siyuan-note/siyuan/kernel/util"
)
func MarkText(text string, keyword string, beforeLen int, caseSensitive bool) (pos int, marked string) {
if "" == keyword {
return -1, html.EscapeString(text)
return -1, util.EscapeHTML(text)
}
text = html.EscapeString(text)
text = util.EscapeHTML(text)
keywords := SplitKeyword(keyword)
marked = EncloseHighlighting(text, keywords, "<mark>", "</mark>", caseSensitive)

View file

@ -16,6 +16,22 @@
package util
import (
"strings"
"github.com/88250/lute/html"
)
func EscapeHTML(s string) string {
if strings.Contains(s, "&amp;") {
return s
}
if strings.ContainsAny(s, "<>\"'") {
return html.EscapeString(s)
}
return s
}
func Reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {