mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
07c7298182
5 changed files with 100 additions and 5 deletions
|
|
@ -700,6 +700,39 @@ export const exportMd = (id: string) => {
|
|||
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);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
label: "RTF",
|
||||
click: () => {
|
||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||
fetchPost("/api/export/exportRTF", {
|
||||
id,
|
||||
}, response => {
|
||||
hideMessage(msgId);
|
||||
openByMobile(response.data.zip);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
label: "EPUB",
|
||||
click: () => {
|
||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||
fetchPost("/api/export/exportEPUB", {
|
||||
id,
|
||||
}, response => {
|
||||
hideMessage(msgId);
|
||||
openByMobile(response.data.zip);
|
||||
});
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,57 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func exportEPUB(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, "epub", ".epub")
|
||||
ret.Data = map[string]interface{}{
|
||||
"name": name,
|
||||
"zip": zipPath,
|
||||
}
|
||||
}
|
||||
|
||||
func exportRTF(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, "rtf", ".rtf")
|
||||
ret.Data = map[string]interface{}{
|
||||
"name": name,
|
||||
"zip": zipPath,
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -251,6 +251,9 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/export/exportOPML", model.CheckAuth, exportOPML)
|
||||
ginServer.Handle("POST", "/api/export/exportOrgMode", model.CheckAuth, exportOrgMode)
|
||||
ginServer.Handle("POST", "/api/export/exportMediaWiki", model.CheckAuth, exportMediaWiki)
|
||||
ginServer.Handle("POST", "/api/export/exportODT", model.CheckAuth, exportODT)
|
||||
ginServer.Handle("POST", "/api/export/exportRTF", model.CheckAuth, exportRTF)
|
||||
ginServer.Handle("POST", "/api/export/exportEPUB", model.CheckAuth, exportEPUB)
|
||||
|
||||
ginServer.Handle("POST", "/api/import/importStdMd", model.CheckAuth, model.CheckReadonly, importStdMd)
|
||||
ginServer.Handle("POST", "/api/import/importData", model.CheckAuth, model.CheckReadonly, importData)
|
||||
|
|
|
|||
|
|
@ -1997,6 +1997,7 @@ func exportPandocConvertZip(boxID, baseFolderName string, docPaths []string,
|
|||
box := Conf.Box(boxID)
|
||||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName+ext)
|
||||
os.RemoveAll(exportFolder)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
|
|
@ -2029,15 +2030,17 @@ func exportPandocConvertZip(boxID, baseFolderName string, docPaths []string,
|
|||
}
|
||||
|
||||
// 调用 Pandoc 进行格式转换
|
||||
output, err := util.Pandoc(pandocFrom, pandocTo, md)
|
||||
output, err := util.Pandoc(pandocFrom, pandocTo, writePath, md)
|
||||
if nil != err {
|
||||
logging.LogErrorf("pandoc failed: %s", err)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
"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 {
|
||||
ret = content
|
||||
return
|
||||
|
|
@ -35,6 +35,11 @@ func Pandoc(from, to, content string) (ret string, err error) {
|
|||
args := []string{
|
||||
"--from", from,
|
||||
"--to", to,
|
||||
"-s",
|
||||
}
|
||||
|
||||
if "" != o {
|
||||
args = append(args, "-o", o)
|
||||
}
|
||||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue