فهرست منبع

:art: Support for exporting ODT Fix https://github.com/siyuan-note/siyuan/issues/8133

Liang Ding 2 سال پیش
والد
کامیت
847be4b939
5فایلهای تغییر یافته به همراه40 افزوده شده و 5 حذف شده
  1. 11 0
      app/src/menus/commonMenuItem.ts
  2. 17 0
      kernel/api/export.go
  3. 1 0
      kernel/api/router.go
  4. 6 4
      kernel/model/export.go
  5. 5 1
      kernel/util/pandoc.go

+ 11 - 0
app/src/menus/commonMenuItem.ts

@@ -700,6 +700,17 @@ export const exportMd = (id: string) => {
                             openByMobile(response.data.zip);
                             openByMobile(response.data.zip);
                         });
                         });
                     }
                     }
+                }, {
+                    label: "ODT",
+                    click: () => {
+                        const msgId = showMessage(window.siyuan.languages.exporting, -1);
+                        fetchPost("/api/export/exportODT", {
+                            id,
+                        }, response => {
+                            hideMessage(msgId);
+                            openByMobile(response.data.zip);
+                        });
+                    }
                 },
                 },
                 ]
                 ]
             }
             }

+ 17 - 0
kernel/api/export.go

@@ -31,6 +31,23 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 )
 
 
+func exportODT(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	id := arg["id"].(string)
+	name, zipPath := model.ExportPandocConvertZip(id, "odt", ".odt")
+	ret.Data = map[string]interface{}{
+		"name": name,
+		"zip":  zipPath,
+	}
+}
+
 func exportMediaWiki(c *gin.Context) {
 func exportMediaWiki(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 0
kernel/api/router.go

@@ -251,6 +251,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/export/exportOPML", model.CheckAuth, exportOPML)
 	ginServer.Handle("POST", "/api/export/exportOPML", model.CheckAuth, exportOPML)
 	ginServer.Handle("POST", "/api/export/exportOrgMode", model.CheckAuth, exportOrgMode)
 	ginServer.Handle("POST", "/api/export/exportOrgMode", model.CheckAuth, exportOrgMode)
 	ginServer.Handle("POST", "/api/export/exportMediaWiki", model.CheckAuth, exportMediaWiki)
 	ginServer.Handle("POST", "/api/export/exportMediaWiki", model.CheckAuth, exportMediaWiki)
+	ginServer.Handle("POST", "/api/export/exportODT", model.CheckAuth, exportODT)
 
 
 	ginServer.Handle("POST", "/api/import/importStdMd", model.CheckAuth, model.CheckReadonly, importStdMd)
 	ginServer.Handle("POST", "/api/import/importStdMd", model.CheckAuth, model.CheckReadonly, importStdMd)
 	ginServer.Handle("POST", "/api/import/importData", model.CheckAuth, model.CheckReadonly, importData)
 	ginServer.Handle("POST", "/api/import/importData", model.CheckAuth, model.CheckReadonly, importData)

+ 6 - 4
kernel/model/export.go

@@ -2029,15 +2029,17 @@ func exportPandocConvertZip(boxID, baseFolderName string, docPaths []string,
 		}
 		}
 
 
 		// 调用 Pandoc 进行格式转换
 		// 调用 Pandoc 进行格式转换
-		output, err := util.Pandoc(pandocFrom, pandocTo, md)
+		output, err := util.Pandoc(pandocFrom, pandocTo, writePath, md)
 		if nil != err {
 		if nil != err {
 			logging.LogErrorf("pandoc failed: %s", err)
 			logging.LogErrorf("pandoc failed: %s", err)
 			continue
 			continue
 		}
 		}
 
 
-		if err := gulu.File.WriteFileSafer(writePath, gulu.Str.ToBytes(output), 0644); nil != err {
-			logging.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
-			continue
+		if "odt" != pandocTo && "epub" != pandocTo && "rtf" != pandocTo {
+			if err := gulu.File.WriteFileSafer(writePath, gulu.Str.ToBytes(output), 0644); nil != err {
+				logging.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
+				continue
+			}
 		}
 		}
 
 
 		// 解析导出后的标准 Markdown,汇总 assets
 		// 解析导出后的标准 Markdown,汇总 assets

+ 5 - 1
kernel/util/pandoc.go

@@ -26,7 +26,7 @@ import (
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/logging"
 )
 )
 
 
-func Pandoc(from, to, content string) (ret string, err error) {
+func Pandoc(from, to, o, content string) (ret string, err error) {
 	if "" == from || "" == to || "md" == to {
 	if "" == from || "" == to || "md" == to {
 		ret = content
 		ret = content
 		return
 		return
@@ -37,6 +37,10 @@ func Pandoc(from, to, content string) (ret string, err error) {
 		"--to", to,
 		"--to", to,
 	}
 	}
 
 
+	if "" != o {
+		args = append(args, "-o", o)
+	}
+
 	pandoc := exec.Command(PandocBinPath, args...)
 	pandoc := exec.Command(PandocBinPath, args...)
 	gulu.CmdAttr(pandoc)
 	gulu.CmdAttr(pandoc)
 	pandoc.Stdin = bytes.NewBufferString(content)
 	pandoc.Stdin = bytes.NewBufferString(content)