mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 00:32:19 +08:00
🎨 支持合并子文档导出 Word/PDF https://github.com/siyuan-note/siyuan/issues/3219
This commit is contained in:
parent
b6d961f347
commit
dede06d20b
@ -160,7 +160,11 @@ func exportDocx(c *gin.Context) {
|
||||
id := arg["id"].(string)
|
||||
savePath := arg["savePath"].(string)
|
||||
removeAssets := arg["removeAssets"].(bool)
|
||||
err := model.ExportDocx(id, savePath, removeAssets)
|
||||
merge := false
|
||||
if nil != arg["merge"] {
|
||||
merge = arg["merge"].(bool)
|
||||
}
|
||||
err := model.ExportDocx(id, savePath, removeAssets, merge)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
@ -180,7 +184,7 @@ func exportMdHTML(c *gin.Context) {
|
||||
|
||||
id := arg["id"].(string)
|
||||
savePath := arg["savePath"].(string)
|
||||
name, content := model.ExportMarkdownHTML(id, savePath, false)
|
||||
name, content := model.ExportMarkdownHTML(id, savePath, false, false)
|
||||
ret.Data = map[string]interface{}{
|
||||
"id": id,
|
||||
"name": name,
|
||||
@ -229,10 +233,14 @@ func exportPreviewHTML(c *gin.Context) {
|
||||
|
||||
id := arg["id"].(string)
|
||||
keepFold := false
|
||||
if arg["keepFold"] != nil {
|
||||
if nil != arg["keepFold"] {
|
||||
keepFold = arg["keepFold"].(bool)
|
||||
}
|
||||
name, content := model.ExportHTML(id, "", true, keepFold)
|
||||
merge := false
|
||||
if nil != arg["merge"] {
|
||||
merge = arg["merge"].(bool)
|
||||
}
|
||||
name, content := model.ExportHTML(id, "", true, keepFold, merge)
|
||||
// 导出 PDF 预览时点击块引转换后的脚注跳转不正确 https://github.com/siyuan-note/siyuan/issues/5894
|
||||
content = strings.ReplaceAll(content, "http://"+util.LocalHost+":"+util.ServerPort+"/#", "#")
|
||||
|
||||
@ -256,10 +264,14 @@ func exportHTML(c *gin.Context) {
|
||||
pdf := arg["pdf"].(bool)
|
||||
savePath := arg["savePath"].(string)
|
||||
keepFold := false
|
||||
if arg["keepFold"] != nil {
|
||||
if nil != arg["keepFold"] {
|
||||
keepFold = arg["keepFold"].(bool)
|
||||
}
|
||||
name, content := model.ExportHTML(id, savePath, pdf, keepFold)
|
||||
merge := false
|
||||
if nil != arg["merge"] {
|
||||
merge = arg["merge"].(bool)
|
||||
}
|
||||
name, content := model.ExportHTML(id, savePath, pdf, keepFold, merge)
|
||||
ret.Data = map[string]interface{}{
|
||||
"id": id,
|
||||
"name": name,
|
||||
|
@ -194,7 +194,7 @@ func Preview(id string) string {
|
||||
return luteEngine.ProtylePreview(tree, luteEngine.RenderOptions)
|
||||
}
|
||||
|
||||
func ExportDocx(id, savePath string, removeAssets bool) (err error) {
|
||||
func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {
|
||||
if !util.IsValidPandocBin(Conf.Export.PandocBin) {
|
||||
return errors.New(Conf.Language(115))
|
||||
}
|
||||
@ -204,7 +204,7 @@ func ExportDocx(id, savePath string, removeAssets bool) (err error) {
|
||||
return
|
||||
}
|
||||
defer os.Remove(tmpDir)
|
||||
name, content := ExportMarkdownHTML(id, tmpDir, true)
|
||||
name, content := ExportMarkdownHTML(id, tmpDir, true, merge)
|
||||
|
||||
tmpDocxPath := filepath.Join(tmpDir, name+".docx")
|
||||
args := []string{ // pandoc -f html --resource-path=请从这里开始 请从这里开始\index.html -o test.docx
|
||||
@ -237,9 +237,18 @@ func ExportDocx(id, savePath string, removeAssets bool) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
||||
func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string) {
|
||||
tree, _ := loadTreeByBlockID(id)
|
||||
|
||||
if merge {
|
||||
var mergeErr error
|
||||
tree, mergeErr = mergeSubDocs(tree)
|
||||
if nil != mergeErr {
|
||||
logging.LogErrorf("merge sub docs failed: %s", mergeErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tree = exportTree(tree, true, true, false)
|
||||
name = path.Base(tree.HPath)
|
||||
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
|
||||
@ -329,7 +338,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
||||
return
|
||||
}
|
||||
|
||||
func ExportHTML(id, savePath string, pdf, keepFold bool) (name, dom string) {
|
||||
func ExportHTML(id, savePath string, pdf, keepFold, merge bool) (name, dom string) {
|
||||
savePath = strings.TrimSpace(savePath)
|
||||
tree, _ := loadTreeByBlockID(id)
|
||||
var headings []*ast.Node
|
||||
@ -354,6 +363,14 @@ func ExportHTML(id, savePath string, pdf, keepFold bool) (name, dom string) {
|
||||
}
|
||||
}
|
||||
|
||||
if merge {
|
||||
var mergeErr error
|
||||
tree, mergeErr = mergeSubDocs(tree)
|
||||
if nil != mergeErr {
|
||||
logging.LogErrorf("merge sub docs failed: %s", mergeErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
tree = exportTree(tree, true, true, keepFold)
|
||||
name = path.Base(tree.HPath)
|
||||
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
|
||||
|
Loading…
Reference in New Issue
Block a user