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

This commit is contained in:
Vanessa 2022-12-11 17:52:49 +08:00
commit 99331ce331
5 changed files with 16 additions and 7 deletions

View file

@ -391,6 +391,7 @@ const initWindow = () => {
destroyPrintWindow();
fetchPost("/api/export/addPDFOutline", {
id: ipcData.rootId,
merge: ipcData.mergeSubdocs,
path: pdfFilePath
}, () => {
afterExport(pdfFilePath, msgId);

View file

@ -290,7 +290,11 @@ func addPDFOutline(c *gin.Context) {
id := arg["id"].(string)
path := arg["path"].(string)
err := model.AddPDFOutline(id, path)
merge := false
if nil != arg["merge"] {
merge = arg["merge"].(bool)
}
err := model.AddPDFOutline(id, path, merge)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()

View file

@ -489,7 +489,7 @@ func processIFrame(tree *parse.Tree) {
}
}
func AddPDFOutline(id, p string) (err error) {
func AddPDFOutline(id, p string, merge bool) (err error) {
inFile := p
links, err := api.ListToCLinks(inFile)
if nil != err {
@ -527,6 +527,14 @@ func AddPDFOutline(id, p string) (err error) {
if nil == tree {
return
}
if merge {
var mergeErr error
tree, mergeErr = mergeSubDocs(tree)
if nil != mergeErr {
logging.LogErrorf("merge sub docs failed: %s", mergeErr)
return
}
}
var headings []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {

View file

@ -84,7 +84,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error)
hLevel = 6
}
heading := &ast.Node{Type: ast.NodeHeading, HeadingLevel: hLevel}
heading := &ast.Node{ID: tree.Root.ID, Type: ast.NodeHeading, HeadingLevel: hLevel}
heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(tree.Root.IALAttr("title"))})
tree.Root.PrependChild(heading)
for c := tree.Root.FirstChild; nil != c; c = c.Next {

View file

@ -24,7 +24,6 @@ import (
"sort"
"strings"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/search"
@ -35,9 +34,6 @@ import (
func createDocsByHPath(boxID, hPath, content string) (id string, existed bool, err error) {
hPath = strings.TrimSuffix(hPath, ".sy")
if existed = nil != treenode.GetBlockTreeRootByHPath(boxID, hPath); existed {
hPath += "-" + gulu.Rand.String(7)
}
pathBuilder := bytes.Buffer{}
pathBuilder.WriteString("/")
hPathBuilder := bytes.Buffer{}