mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-31 22:08:48 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
c903101418
7 changed files with 110 additions and 76 deletions
4
app/stage/protyle/js/lute/lute.min.js
vendored
4
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
|
||||
github.com/88250/lute v1.7.7-0.20240613162043-6b9d74391f35
|
||||
github.com/88250/lute v1.7.7-0.20240616044942-3dd5162f4c3d
|
||||
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
|
||||
|
|
|
|||
|
|
@ -12,8 +12,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.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
|
||||
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
|
||||
github.com/88250/lute v1.7.7-0.20240613162043-6b9d74391f35 h1:4zkvrImK6HE1C4ht7B5HyHOp036JnUSFnbBEGbaMgN4=
|
||||
github.com/88250/lute v1.7.7-0.20240613162043-6b9d74391f35/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||
github.com/88250/lute v1.7.7-0.20240616044942-3dd5162f4c3d h1:okl9vdazsVoEHItsLXsMS8x6ertUGz2HHSQHtyCxc5M=
|
||||
github.com/88250/lute v1.7.7-0.20240616044942-3dd5162f4c3d/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
|
||||
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=
|
||||
|
|
|
|||
|
|
@ -1932,62 +1932,9 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
|
|||
luteEngine := NewLute()
|
||||
ret = tree
|
||||
id := tree.Root.ID
|
||||
var unlinks []*ast.Node
|
||||
|
||||
// 解析查询嵌入节点
|
||||
ast.Walk(ret.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || ast.NodeBlockQueryEmbed != n.Type {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
var defMd string
|
||||
stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr()
|
||||
stmt = html.UnescapeString(stmt)
|
||||
stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
|
||||
embedBlocks := searchEmbedBlock(n.ID, stmt, nil, 0, false)
|
||||
if 1 > len(embedBlocks) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
defMdBuf := bytes.Buffer{}
|
||||
for _, def := range embedBlocks {
|
||||
defMdBuf.WriteString(renderBlockMarkdownR(def.Block.ID))
|
||||
defMdBuf.WriteString("\n\n")
|
||||
}
|
||||
defMd = defMdBuf.String()
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
lines := strings.Split(defMd, "\n")
|
||||
for i, line := range lines {
|
||||
if 0 == blockEmbedMode { // 原始文本
|
||||
buf.WriteString(line)
|
||||
} else { // Blockquote
|
||||
buf.WriteString("> " + line)
|
||||
}
|
||||
if i < len(lines)-1 {
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
}
|
||||
buf.WriteString("\n\n")
|
||||
|
||||
refTree := parse.Parse("", buf.Bytes(), luteEngine.ParseOptions)
|
||||
var children []*ast.Node
|
||||
for c := refTree.Root.FirstChild; nil != c; c = c.Next {
|
||||
children = append(children, c)
|
||||
}
|
||||
for _, c := range children {
|
||||
if ast.NodeDocument == c.Type {
|
||||
continue
|
||||
}
|
||||
n.InsertBefore(c)
|
||||
}
|
||||
unlinks = append(unlinks, n)
|
||||
return ast.WalkSkipChildren
|
||||
})
|
||||
for _, n := range unlinks {
|
||||
n.Unlink()
|
||||
}
|
||||
unlinks = nil
|
||||
resolveEmbedR(ret.Root, blockEmbedMode, luteEngine, &[]string{})
|
||||
|
||||
// 收集引用转脚注
|
||||
var refFootnotes []*refAsFootnotes
|
||||
|
|
@ -1998,6 +1945,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
|
|||
collectFootnotesDefs(ret.ID, &refFootnotes, &treeCache, &depth)
|
||||
}
|
||||
|
||||
var unlinks []*ast.Node
|
||||
ast.Walk(ret.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
|
|
@ -2393,7 +2341,7 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, rootID string, blockR
|
|||
stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
|
||||
sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit)
|
||||
for _, b := range sqlBlocks {
|
||||
subNodes := renderBlockMarkdownR0(b.ID, &rendered)
|
||||
subNodes := renderBlockMarkdownR(b.ID, &rendered)
|
||||
for _, subNode := range subNodes {
|
||||
if ast.NodeListItem == subNode.Type {
|
||||
parentList := &ast.Node{Type: ast.NodeList, ListData: &ast.ListData{Typ: subNode.ListData.Typ}}
|
||||
|
|
|
|||
|
|
@ -1640,13 +1640,19 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
}
|
||||
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
||||
|
||||
// 刷新文档关联的数据库 https://github.com/siyuan-note/siyuan/issues/11731
|
||||
allRemoveRootIDs := []string{tree.ID}
|
||||
allRemoveRootIDs = append(allRemoveRootIDs, removeIDs...)
|
||||
for _, rootID := range allRemoveRootIDs {
|
||||
if removeTree, _ := LoadTreeByBlockID(rootID); nil != removeTree {
|
||||
syncDelete2AttributeView(removeTree.Root)
|
||||
removeTree, _ := LoadTreeByBlockID(rootID)
|
||||
if nil == removeTree {
|
||||
continue
|
||||
}
|
||||
|
||||
// 刷新文档关联的数据库 https://github.com/siyuan-note/siyuan/issues/11731
|
||||
syncDelete2AttributeView(removeTree.Root)
|
||||
|
||||
// 解绑数据库关联
|
||||
removeAvBlockRel(removeTree.Root)
|
||||
}
|
||||
|
||||
if existChildren {
|
||||
|
|
|
|||
|
|
@ -165,21 +165,83 @@ func renderBlockContentByNodes(nodes []*ast.Node) string {
|
|||
return buf.String()
|
||||
}
|
||||
|
||||
func renderBlockMarkdownR(id string) string {
|
||||
var rendered []string
|
||||
nodes := renderBlockMarkdownR0(id, &rendered)
|
||||
buf := bytes.Buffer{}
|
||||
buf.Grow(4096)
|
||||
luteEngine := NewLute()
|
||||
for _, n := range nodes {
|
||||
md := treenode.FormatNode(n, luteEngine)
|
||||
buf.WriteString(md)
|
||||
buf.WriteString("\n\n")
|
||||
func resolveEmbedR(n *ast.Node, blockEmbedMode int, luteEngine *lute.Lute, resolved *[]string) {
|
||||
var children []*ast.Node
|
||||
if ast.NodeHeading == n.Type {
|
||||
children = append(children, n)
|
||||
children = append(children, treenode.HeadingChildren(n)...)
|
||||
} else if ast.NodeDocument == n.Type {
|
||||
for c := n.FirstChild; nil != c; c = c.Next {
|
||||
children = append(children, c)
|
||||
}
|
||||
} else {
|
||||
children = append(children, n)
|
||||
}
|
||||
return buf.String()
|
||||
|
||||
for _, child := range children {
|
||||
var unlinks []*ast.Node
|
||||
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if ast.NodeBlockQueryEmbed == n.Type {
|
||||
if gulu.Str.Contains(n.ID, *resolved) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
*resolved = append(*resolved, n.ID)
|
||||
|
||||
stmt := n.ChildByType(ast.NodeBlockQueryEmbedScript).TokensStr()
|
||||
stmt = html.UnescapeString(stmt)
|
||||
stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
|
||||
sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit)
|
||||
for _, sqlBlock := range sqlBlocks {
|
||||
md := sqlBlock.Markdown
|
||||
|
||||
if "d" == sqlBlock.Type {
|
||||
subTree, _ := LoadTreeByBlockID(sqlBlock.ID)
|
||||
md, _ = lute.FormatNodeSync(subTree.Root, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
} // 标题块不需要再单独解析,直接使用 Markdown,函数开头处会处理
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
lines := strings.Split(md, "\n")
|
||||
for i, line := range lines {
|
||||
if 0 == blockEmbedMode { // 使用原始文本
|
||||
buf.WriteString(line)
|
||||
} else { // 使用引述块
|
||||
buf.WriteString("> " + line)
|
||||
}
|
||||
if i < len(lines)-1 {
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
}
|
||||
buf.WriteString("\n\n")
|
||||
|
||||
subTree := parse.Parse("", buf.Bytes(), luteEngine.ParseOptions)
|
||||
var inserts []*ast.Node
|
||||
for subNode := subTree.Root.FirstChild; nil != subNode; subNode = subNode.Next {
|
||||
if ast.NodeKramdownBlockIAL != subNode.Type {
|
||||
inserts = append(inserts, subNode)
|
||||
}
|
||||
}
|
||||
for _, insert := range inserts {
|
||||
n.InsertBefore(insert)
|
||||
resolveEmbedR(insert, blockEmbedMode, luteEngine, resolved)
|
||||
}
|
||||
}
|
||||
unlinks = append(unlinks, n)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
for _, unlink := range unlinks {
|
||||
unlink.Unlink()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func renderBlockMarkdownR0(id string, rendered *[]string) (ret []*ast.Node) {
|
||||
func renderBlockMarkdownR(id string, rendered *[]string) (ret []*ast.Node) {
|
||||
if gulu.Str.Contains(id, *rendered) {
|
||||
return
|
||||
}
|
||||
|
|
@ -225,7 +287,7 @@ func renderBlockMarkdownR0(id string, rendered *[]string) (ret []*ast.Node) {
|
|||
stmt = strings.ReplaceAll(stmt, editor.IALValEscNewLine, "\n")
|
||||
sqlBlocks := sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit)
|
||||
for _, sqlBlock := range sqlBlocks {
|
||||
subNodes := renderBlockMarkdownR0(sqlBlock.ID, rendered)
|
||||
subNodes := renderBlockMarkdownR(sqlBlock.ID, rendered)
|
||||
for _, subNode := range subNodes {
|
||||
inserts = append(inserts, subNode)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
|
|
@ -105,6 +106,23 @@ func resetTree(tree *parse.Tree, titleSuffix string) {
|
|||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
var attrViewIDs []string
|
||||
// 绑定镜像数据库
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if ast.NodeAttributeView == n.Type {
|
||||
av.UpsertBlockRel(n.AttributeViewID, n.ID)
|
||||
attrViewIDs = append(attrViewIDs, n.AttributeViewID)
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
// 清空文档绑定的数据库
|
||||
tree.Root.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||
}
|
||||
|
||||
func pagedPaths(localPath string, pageSize int) (ret map[int][]string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue