diff --git a/API.md b/API.md
index d812967e6..a059a4f38 100644
--- a/API.md
+++ b/API.md
@@ -44,6 +44,8 @@
* [List files](#List-files)
* [Export](#Export)
* [Export Markdown](#Export-Markdown)
+* [Conversion](#Conversion)
+ * [Pandoc](#Pandoc)
* [Notification](#Notification)
* [Push message](#Push-message)
* [Push error message](#Push-error-message)
@@ -710,9 +712,10 @@ View API token in Settings - About, request header: `Authorization: T
}
```
- * `id`: Block ID to move
- * `previousID`: The ID of the previous block, used to anchor the insertion position
- * `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot be empty at the same time, if they exist at the same time, `previousID` will be used first
+ * `id`: Block ID to move
+ * `previousID`: The ID of the previous block, used to anchor the insertion position
+ * `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot
+ be empty at the same time, if they exist at the same time, `previousID` will be used first
* Return value
```json
@@ -1014,6 +1017,41 @@ View API token in Settings - About, request header: `Authorization: T
* `hPath`: human-readable path
* `content`: Markdown content
+## Conversion
+
+### Pandoc
+
+* `/api/convert/pandoc`
+* Working directory
+ * Executing the pandoc command will set the working directory to `workspace/temp/convert/pandoc/`
+ * API [`Put file`](#put-file) can be used to write the file to be converted to this directory first
+ * Then call the API for conversion, and the converted file will also be written to this directory
+ * Finally, call the API [`Get file`](#get-file) to get the converted file
+ * Or call the API [Create a document with Markdown](#Create-a-document-with-Markdown)
+ * Or call the internal API `importStdMd` to import the converted folder directly
+* Parameters
+
+ ```json
+ {
+ "args": [
+ "--to", "markdown_strict-raw_html",
+ "foo.epub",
+ "-o", "foo.md"
+ ]
+ }
+ ```
+
+ * `args`: Pandoc command line parameters
+* Return value
+
+ ```json
+ {
+ "code": 0,
+ "msg": "",
+ "data": null
+ }
+ ```
+
## Notification
### Push message
diff --git a/API_zh_CN.md b/API_zh_CN.md
index 340f155ad..971356882 100644
--- a/API_zh_CN.md
+++ b/API_zh_CN.md
@@ -44,6 +44,8 @@
* [列出文件](#列出文件)
* [导出](#导出)
* [导出 Markdown 文本](#导出-markdown-文本)
+* [转换](#转换)
+ * [Pandoc](#Pandoc)
* [通知](#通知)
* [推送消息](#推送消息)
* [推送报错消息](#推送报错消息)
@@ -1008,6 +1010,41 @@
* `hPath`:人类可读的路径
* `content`:Markdown 内容
+## 转换
+
+### Pandoc
+
+* `/api/convert/pandoc`
+* 工作目录
+ * 执行调用 pandoc 命令时工作目录会被设置在 `工作空间/temp/convert/pandoc/` 下
+ * 可先通过 API [`写入文件`](#写入文件) 将待转换文件写入该目录
+ * 然后再调用该 API 进行转换,转换后的文件也会被写入该目录
+ * 最后调用 API [`获取文件`](#获取文件) 获取转换后的文件内容
+ * 或者调用 API [`通过 Markdown 创建文档`](#通过-markdown-创建文档)
+ * 或者调用内部 API `importStdMd` 将转换后的文件夹直接导入
+* 参数
+
+ ```json
+ {
+ "args": [
+ "--to", "markdown_strict-raw_html",
+ "foo.epub",
+ "-o", "foo.md"
+ ]
+ }
+ ```
+
+ * `args`:Pandoc 命令行参数
+* 返回值
+
+ ```json
+ {
+ "code": 0,
+ "msg": "",
+ "data": null
+ }
+ ```
+
## 通知
### 推送消息
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 63b9f3716..0edc23949 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -574,7 +574,7 @@
"kernelFault1": "Your data should be safe, please check whether the network connection and kernel process are normal, and then restart SiYuan",
"kernelFault2": "If the problem persists, please look for help or report bugs here",
"fontSize": "Font Size",
- "fontSizeTip": "The default font size is 16px, this setting affects the editor and exported PDF/HTML font size display",
+ "fontSizeTip": "The default font size is 16, this setting affects the editor and exported PDF/HTML font size display",
"font1": "This setting only affects the font family display in the editor, choose Default to use the theme's font family",
"newNameFile": "The name of the new subdocument is",
"newNameSettingFile": "The name of the new document is",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 7ffc53b83..8bdcaa5b6 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -574,7 +574,7 @@
"kernelFault1": "Sus datos deben estar seguros, verifique si la conexión de red y el proceso del kernel son normales y luego reinicie SiYuan",
"kernelFault2": "Si el problema persiste, busque ayuda o informe de errores aquí",
"fontSize": "Tamaño de la fuente",
- "fontSizeTip": "El tamaño de fuente predeterminado es 16px, esta configuración afecta el editor y la visualización del tamaño de fuente PDF/HTML exportado",
+ "fontSizeTip": "El tamaño de fuente predeterminado es 16, esta configuración afecta el editor y la visualización del tamaño de fuente PDF/HTML exportado",
"font1": "Este ajuste sólo afecta a la visualización de la familia de fuentes en el editor, elija Por defecto para utilizar la familia de fuentes del tema",
"newNameFile": "El nombre del nuevo subdocumento es",
"newNameSettingFile": "El nombre del nuevo documento es",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index b761dc33f..d7451f56e 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -574,7 +574,7 @@
"kernelFault1": "Vos données doivent être en sécurité, veuillez vérifier si la connexion réseau et le processus du noyau sont normaux, puis redémarrez SiYuan",
"kernelFault2": "Si le problème persiste, veuillez rechercher de l'aide ou signaler les bogues ici",
"fontSize": "Taille de la police",
- "fontSizeTip": "La taille de police par défaut est de 16px, ce paramètre affecte l'éditeur et l'affichage de la taille de police PDF/HTML exportée",
+ "fontSizeTip": "La taille de police par défaut est de 16, ce paramètre affecte l'éditeur et l'affichage de la taille de police PDF/HTML exportée",
"font1": "Ce paramètre n'affecte que l'affichage de la famille de polices dans l'éditeur, choisissez Default pour utiliser la famille de polices du thème.",
"newNameFile": "Le nom du nouveau sous-document est",
"newNameSettingFile": "Le nom du nouveau document est",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 1a858e183..c63a4d931 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -574,7 +574,7 @@
"kernelFault1": "你的數據應該是安全的,請檢查網絡連接和內核進程是否正常,然後重新啟動思源",
"kernelFault2": "如果仍然出現該問題,請在這裡尋求幫助或者報告缺陷",
"fontSize": "字型大小",
- "fontSizeTip": "字號默認為 16px,該設置影響編輯器和導出 PDF/HTML 字體大小顯示",
+ "fontSizeTip": "字號默認為 16,該設置影響編輯器和導出 PDF/HTML 字體大小顯示",
"font1": "該設置僅影響編輯器內字體顯示,選擇 預設 則使用主題自帶字體",
"newNameFile": "新建子文檔名為",
"newNameSettingFile": "新建文檔名為",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 9c44d8354..556883edc 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -574,7 +574,7 @@
"kernelFault1": "你的数据应该是安全的,请检查网络连接和内核进程是否正常,然后重新启动思源",
"kernelFault2": "如果仍然出现该问题,请在这里寻求帮助或者报告缺陷",
"fontSize": "字号",
- "fontSizeTip": "字号默认为 16px,该设置影响编辑器和导出 PDF/HTML 字体大小显示",
+ "fontSizeTip": "字号默认为 16,该设置影响编辑器和导出 PDF/HTML 字体大小显示",
"font1": "该设置仅影响编辑器内字体显示,选择 默认 则使用主题自带字体",
"newNameFile": "新建子文档名为",
"newNameSettingFile": "新建文档名为",
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go
index 6a1512601..40a683b92 100644
--- a/kernel/api/filetree.go
+++ b/kernel/api/filetree.go
@@ -528,6 +528,14 @@ func getDocCreateSavePath(c *gin.Context) {
if "" == docCreateSavePathTpl {
docCreateSavePathTpl = model.Conf.FileTree.DocCreateSavePath
}
+ docCreateSavePathTpl = strings.TrimSpace(docCreateSavePathTpl)
+ if "../" == docCreateSavePathTpl {
+ docCreateSavePathTpl = "../Untitled"
+ }
+ for strings.HasSuffix(docCreateSavePathTpl, "/") {
+ docCreateSavePathTpl = strings.TrimSuffix(docCreateSavePathTpl, "/")
+ docCreateSavePathTpl = strings.TrimSpace(docCreateSavePathTpl)
+ }
p, err := model.RenderGoTemplate(docCreateSavePathTpl)
if nil != err {
diff --git a/kernel/api/notebook.go b/kernel/api/notebook.go
index 80196235b..0dee040e6 100644
--- a/kernel/api/notebook.go
+++ b/kernel/api/notebook.go
@@ -300,6 +300,15 @@ func setNotebookConf(c *gin.Context) {
}
}
+ boxConf.DocCreateSavePath = strings.TrimSpace(boxConf.DocCreateSavePath)
+ if "../" == boxConf.DocCreateSavePath {
+ boxConf.DocCreateSavePath = "../Untitled"
+ }
+ for strings.HasSuffix(boxConf.DocCreateSavePath, "/") {
+ boxConf.DocCreateSavePath = strings.TrimSuffix(boxConf.DocCreateSavePath, "/")
+ boxConf.DocCreateSavePath = strings.TrimSpace(boxConf.DocCreateSavePath)
+ }
+
box.SaveConf(boxConf)
ret.Data = boxConf
}
diff --git a/kernel/api/pandoc.go b/kernel/api/pandoc.go
new file mode 100644
index 000000000..bd672b1bd
--- /dev/null
+++ b/kernel/api/pandoc.go
@@ -0,0 +1,49 @@
+// SiYuan - Build Your Eternal Digital Garden
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package api
+
+import (
+ "net/http"
+
+ "github.com/88250/gulu"
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func pandoc(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ arg, ok := util.JsonArg(c, ret)
+ if !ok {
+ return
+ }
+
+ pandocArgs := arg["args"].([]interface{})
+ var args []string
+ for _, v := range pandocArgs {
+ args = append(args, v.(string))
+ }
+
+ err := util.ConvertPandoc(args...)
+ if nil != err {
+ ret.Code = -1
+ ret.Msg = err.Error()
+ return
+ }
+ return
+}
diff --git a/kernel/api/router.go b/kernel/api/router.go
index ffd934bd5..0a0f22cc3 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -259,6 +259,8 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/import/importData", model.CheckAuth, model.CheckReadonly, importData)
ginServer.Handle("POST", "/api/import/importSY", model.CheckAuth, model.CheckReadonly, importSY)
+ ginServer.Handle("POST", "/api/convert/pandoc", model.CheckAuth, model.CheckReadonly, pandoc)
+
ginServer.Handle("POST", "/api/template/render", model.CheckAuth, renderTemplate)
ginServer.Handle("POST", "/api/template/docSaveAsTemplate", model.CheckAuth, model.CheckReadonly, docSaveAsTemplate)
ginServer.Handle("POST", "/api/template/renderSprig", model.CheckAuth, model.CheckReadonly, renderSprig)
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 4fd26b616..ba2e925a9 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -265,6 +265,9 @@ func setFiletree(c *gin.Context) {
}
fileTree.DocCreateSavePath = strings.TrimSpace(fileTree.DocCreateSavePath)
+ if "../" == fileTree.DocCreateSavePath {
+ fileTree.DocCreateSavePath = "../Untitled"
+ }
for strings.HasSuffix(fileTree.DocCreateSavePath, "/") {
fileTree.DocCreateSavePath = strings.TrimSuffix(fileTree.DocCreateSavePath, "/")
fileTree.DocCreateSavePath = strings.TrimSpace(fileTree.DocCreateSavePath)
diff --git a/kernel/conf/ai.go b/kernel/conf/ai.go
index 9214f4c15..cd1bf8d08 100644
--- a/kernel/conf/ai.go
+++ b/kernel/conf/ai.go
@@ -19,6 +19,8 @@ package conf
import (
"os"
"strconv"
+
+ "github.com/sashabaranov/go-openai"
)
type AI struct {
@@ -37,6 +39,7 @@ type OpenAI struct {
func NewAI() *AI {
openAI := &OpenAI{
APITimeout: 30,
+ APIModel: openai.GPT3Dot5Turbo,
APIBaseURL: "https://api.openai.com/v1",
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index c99edef12..8fe8dc65f 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -175,6 +175,9 @@ func InitConf() {
Conf.FileTree.MaxOpenTabCount = 32
}
Conf.FileTree.DocCreateSavePath = strings.TrimSpace(Conf.FileTree.DocCreateSavePath)
+ if "../" == Conf.FileTree.DocCreateSavePath {
+ Conf.FileTree.DocCreateSavePath = "../Untitled"
+ }
for strings.HasSuffix(Conf.FileTree.DocCreateSavePath, "/") {
Conf.FileTree.DocCreateSavePath = strings.TrimSuffix(Conf.FileTree.DocCreateSavePath, "/")
Conf.FileTree.DocCreateSavePath = strings.TrimSpace(Conf.FileTree.DocCreateSavePath)
@@ -339,7 +342,7 @@ func InitConf() {
Conf.AI = conf.NewAI()
}
if "" == Conf.AI.OpenAI.APIModel {
- Conf.AI.OpenAI.APIModel = openai.GPT4
+ Conf.AI.OpenAI.APIModel = openai.GPT3Dot5Turbo
}
if "" != Conf.AI.OpenAI.APIKey {
diff --git a/kernel/util/pandoc.go b/kernel/util/pandoc.go
index c9d68cf4e..f46d6208d 100644
--- a/kernel/util/pandoc.go
+++ b/kernel/util/pandoc.go
@@ -18,6 +18,8 @@ package util
import (
"bytes"
+ "errors"
+ "os"
"os/exec"
"path/filepath"
"strings"
@@ -26,6 +28,27 @@ import (
"github.com/siyuan-note/logging"
)
+func ConvertPandoc(args ...string) (err error) {
+ if "" == PandocBinPath || ContainerStd != Container {
+ return errors.New("not found executable pandoc")
+ }
+
+ pandoc := exec.Command(PandocBinPath, args...)
+ gulu.CmdAttr(pandoc)
+ dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc")
+ if err = os.MkdirAll(dir, 0755); nil != err {
+ logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
+ return
+ }
+ pandoc.Dir = dir
+ output, err := pandoc.CombinedOutput()
+ if nil != err {
+ logging.LogErrorf("pandoc convert output [%s]", string(output))
+ return
+ }
+ return
+}
+
func Pandoc(from, to, o, content string) (ret string, err error) {
if "" == from || "" == to || "md" == to {
ret = content