Просмотр исходного кода

:art: Support exporting Markdown after selecting multiple documents https://github.com/siyuan-note/siyuan/issues/12912

Daniel 8 месяцев назад
Родитель
Сommit
a32ceb8e2f
4 измененных файлов с 51 добавлено и 5 удалено
  1. 1 1
      app/src/menus/navigation.ts
  2. 24 2
      kernel/api/export.go
  3. 2 1
      kernel/api/router.go
  4. 24 1
      kernel/model/export.go

+ 1 - 1
app/src/menus/navigation.ts

@@ -335,7 +335,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
             icon: "iconMarkdown",
             icon: "iconMarkdown",
             click: () => {
             click: () => {
                 const msgId = showMessage(window.siyuan.languages.exporting, -1);
                 const msgId = showMessage(window.siyuan.languages.exporting, -1);
-                fetchPost("/api/export/batchExportMd", {
+                fetchPost("/api/export/exportNotebookMd", {
                     notebook: notebookId,
                     notebook: notebookId,
                     path: "/"
                     path: "/"
                 }, response => {
                 }, response => {

+ 24 - 2
kernel/api/export.go

@@ -307,7 +307,7 @@ func exportResources(c *gin.Context) {
 	}
 	}
 }
 }
 
 
-func batchExportMd(c *gin.Context) {
+func exportNotebookMd(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)
 
 
@@ -318,13 +318,35 @@ func batchExportMd(c *gin.Context) {
 
 
 	notebook := arg["notebook"].(string)
 	notebook := arg["notebook"].(string)
 	p := arg["path"].(string)
 	p := arg["path"].(string)
-	zipPath := model.BatchExportMarkdown(notebook, p)
+	zipPath := model.ExportNotebookMarkdown(notebook, p)
 	ret.Data = map[string]interface{}{
 	ret.Data = map[string]interface{}{
 		"name": path.Base(zipPath),
 		"name": path.Base(zipPath),
 		"zip":  zipPath,
 		"zip":  zipPath,
 	}
 	}
 }
 }
 
 
+func exportMds(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	idsArg := arg["ids"].([]interface{})
+	var ids []string
+	for _, id := range idsArg {
+		ids = append(ids, id.(string))
+	}
+
+	name, zipPath := model.BatchExportPandocConvertZip(ids, "", ".md")
+	ret.Data = map[string]interface{}{
+		"name": name,
+		"zip":  zipPath,
+	}
+}
+
 func exportMd(c *gin.Context) {
 func exportMd(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)

+ 2 - 1
kernel/api/router.go

@@ -277,7 +277,8 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/asset/fullReindexAssetContent", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, fullReindexAssetContent)
 	ginServer.Handle("POST", "/api/asset/fullReindexAssetContent", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, fullReindexAssetContent)
 	ginServer.Handle("POST", "/api/asset/statAsset", model.CheckAuth, model.CheckAdminRole, statAsset)
 	ginServer.Handle("POST", "/api/asset/statAsset", model.CheckAuth, model.CheckAdminRole, statAsset)
 
 
-	ginServer.Handle("POST", "/api/export/batchExportMd", model.CheckAuth, model.CheckAdminRole, batchExportMd)
+	ginServer.Handle("POST", "/api/export/exportNotebookMd", model.CheckAuth, model.CheckAdminRole, exportNotebookMd)
+	ginServer.Handle("POST", "/api/export/exportMds", model.CheckAuth, model.CheckAdminRole, exportMds)
 	ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, model.CheckAdminRole, exportMd)
 	ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, model.CheckAdminRole, exportMd)
 	ginServer.Handle("POST", "/api/export/exportSY", model.CheckAuth, model.CheckAdminRole, exportSY)
 	ginServer.Handle("POST", "/api/export/exportSY", model.CheckAuth, model.CheckAdminRole, exportSY)
 	ginServer.Handle("POST", "/api/export/exportNotebookSY", model.CheckAuth, model.CheckAdminRole, exportNotebookSY)
 	ginServer.Handle("POST", "/api/export/exportNotebookSY", model.CheckAuth, model.CheckAdminRole, exportNotebookSY)

+ 24 - 1
kernel/model/export.go

@@ -1382,6 +1382,29 @@ func ExportStdMarkdown(id string) string {
 		Conf.Export.AddTitle, nil)
 		Conf.Export.AddTitle, nil)
 }
 }
 
 
+func BatchExportPandocConvertZip(ids []string, pandocTo, ext string) (name, zipPath string) {
+	block := treenode.GetBlockTree(ids[0])
+	box := Conf.Box(block.BoxID)
+	baseFolderName := path.Base(block.HPath)
+	if "." == baseFolderName {
+		baseFolderName = path.Base(block.Path)
+	}
+	var docPaths []string
+
+	bts := treenode.GetBlockTrees(ids)
+	for _, bt := range bts {
+		docFiles := box.ListFiles(strings.TrimSuffix(bt.Path, ".sy"))
+		for _, docFile := range docFiles {
+			docPaths = append(docPaths, docFile.path)
+		}
+	}
+	docPaths = util.FilterSelfChildDocs(docPaths)
+
+	zipPath = exportPandocConvertZip(false, box.ID, baseFolderName, docPaths, "gfm+footnotes+hard_line_breaks", pandocTo, ext)
+	name = strings.TrimSuffix(filepath.Base(block.Path), ".sy")
+	return
+}
+
 func ExportPandocConvertZip(id, pandocTo, ext string) (name, zipPath string) {
 func ExportPandocConvertZip(id, pandocTo, ext string) (name, zipPath string) {
 	block := treenode.GetBlockTree(id)
 	block := treenode.GetBlockTree(id)
 	if nil == block {
 	if nil == block {
@@ -1406,7 +1429,7 @@ func ExportPandocConvertZip(id, pandocTo, ext string) (name, zipPath string) {
 	return
 	return
 }
 }
 
 
-func BatchExportMarkdown(boxID, folderPath string) (zipPath string) {
+func ExportNotebookMarkdown(boxID, folderPath string) (zipPath string) {
 	box := Conf.Box(boxID)
 	box := Conf.Box(boxID)
 
 
 	var baseFolderName string
 	var baseFolderName string