Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 桌面端内置 Pandoc 可执行文件 https://github.com/siyuan-note/siyuan/issues/5835

Liang Dingd134045a60fb
diff --git a/app/electron-builder-darwin-arm64.yml b/app/electron-builder-darwin-arm64.yml
index 706b9b123c..761d3bc20c 100644
--- a/app/electron-builder-darwin-arm64.yml
+++ b/app/electron-builder-darwin-arm64.yml
@@ -50,3 +50,5 @@ extraResources:
- from: "appearance/themes/daylight"
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
+ - from: "pandoc/pandoc-darwin-amd64.zip"
+ to: "pandoc.zip"
\ No newline at end of file
diff --git a/app/electron-builder-darwin.yml b/app/electron-builder-darwin.yml
index 0479400086..c77baf539a 100644
--- a/app/electron-builder-darwin.yml
+++ b/app/electron-builder-darwin.yml
@@ -49,3 +49,5 @@ extraResources:
- from: "appearance/themes/daylight"
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
+ - from: "pandoc/pandoc-darwin-amd64.zip"
+ to: "pandoc.zip"
\ No newline at end of file
diff --git a/app/electron-builder-linux.yml b/app/electron-builder-linux.yml
index 710de3f78b..da0eff3367 100644
--- a/app/electron-builder-linux.yml
+++ b/app/electron-builder-linux.yml
@@ -48,3 +48,5 @@ extraResources:
- from: "appearance/themes/daylight"
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
+ - from: "pandoc/pandoc-linux-amd64.zip"
+ to: "pandoc.zip"
\ No newline at end of file
diff --git a/app/electron-builder-win32.yml b/app/electron-builder-win32.yml
index 4267fe71c0..00dda7539c 100644
--- a/app/electron-builder-win32.yml
+++ b/app/electron-builder-win32.yml
@@ -62,3 +62,5 @@ extraResources:
- from: "appearance/themes/daylight"
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
+ - from: "pandoc/pandoc-windows-386.zip"
+ to: "pandoc.zip"
\ No newline at end of file
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index 11f50dee8f..1257c95f5a 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -62,3 +62,5 @@ extraResources:
- from: "appearance/themes/daylight"
to: "appearance/themes/daylight"
filter: "!**/{.DS_Store,custom.css}"
+ - from: "pandoc/pandoc-windows-amd64.zip"
+ to: "pandoc.zip"
\ No newline at end of file
diff --git a/app/pandoc/pandoc-darwin-amd64.zip b/app/pandoc/pandoc-darwin-amd64.zip
new file mode 100644
index 0000000000..9d2efc8268
Binary files /dev/null and b/app/pandoc/pandoc-darwin-amd64.zip differ
diff --git a/app/pandoc/pandoc-linux-amd64.zip b/app/pandoc/pandoc-linux-amd64.zip
new file mode 100644
index 0000000000..aa64f15975
Binary files /dev/null and b/app/pandoc/pandoc-linux-amd64.zip differ
diff --git a/app/pandoc/pandoc-windows-386.zip b/app/pandoc/pandoc-windows-386.zip
new file mode 100644
index 0000000000..557f65d686
Binary files /dev/null and b/app/pandoc/pandoc-windows-386.zip differ
diff --git a/app/pandoc/pandoc-windows-amd64.zip b/app/pandoc/pandoc-windows-amd64.zip
new file mode 100644
index 0000000000..82486b0145
Binary files /dev/null and b/app/pandoc/pandoc-windows-amd64.zip differ
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 6ecd3917f7..8aad7006dc 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -127,10 +127,8 @@ func setExport(c *gin.Context) {
if "" != export.PandocBin {
if !util.IsValidPandocBin(export.PandocBin) {
- ret.Code = -1
- ret.Msg = fmt.Sprintf(model.Conf.Language(117), export.PandocBin)
- ret.Data = map[string]interface{}{"closeTimeout": 5000}
- return
+ util.PushErrMsg(fmt.Sprintf(model.Conf.Language(117), export.PandocBin), 5000)
+ export.PandocBin = util.PandocBinPath
}
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 82ed35f03f..226ee6afd0 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -187,6 +187,9 @@ func InitConf() {
// 废弃导出选项引用块转换为原始块和引述块 https://github.com/siyuan-note/siyuan/issues/3155
Conf.Export.BlockRefMode = 4 // 改为脚注
}
+ if "" == Conf.Export.PandocBin {
+ Conf.Export.PandocBin = util.PandocBinPath
+ }
if 9 > Conf.Editor.FontSize || 72 < Conf.Editor.FontSize {
Conf.Editor.FontSize = 16
}
diff --git a/kernel/util/path.go b/kernel/util/path.go
index bfdcd09fbe..4d501895ee 100644
--- a/kernel/util/path.go
+++ b/kernel/util/path.go
@@ -20,7 +20,6 @@ import (
"bytes"
"net"
"os"
- "os/exec"
"path"
"strings"
@@ -135,17 +134,3 @@ func TimeFromID(id string) (ret string) {
ret = id[:14]
return
}
-
-func IsValidPandocBin(binPath string) bool {
- if "" == binPath {
- return false
- }
-
- cmd := exec.Command(binPath, "--version")
- CmdAttr(cmd)
- data, err := cmd.CombinedOutput()
- if nil == err && strings.HasPrefix(string(data), "pandoc") {
- return true
- }
- return false
-}
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 0e4264008b..f93d602809 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -17,6 +17,7 @@
package util
import (
+ "bytes"
"flag"
"log"
"math/rand"
@@ -101,6 +102,7 @@ func Boot() {
initPathDir()
checkPort()
+ go initPandoc()
bootBanner := figure.NewColorFigure("SiYuan", "isometric3", "green", true)
logging.LogInfof("\n" + bootBanner.String())
@@ -161,6 +163,7 @@ var (
DBPath string // SQLite 数据库文件路径
HistoryDBPath string // SQLite 历史数据库文件路径
BlockTreePath string // 区块树文件路径
+ PandocBinPath string // Pandoc 可执行文件路径
AppearancePath string // 配置目录下的外观目录 appearance/ 路径
ThemesPath string // 配置目录下的外观目录下的 themes/ 路径
IconsPath string // 配置目录下的外观目录下的 icons/ 路径
@@ -454,3 +457,76 @@ func PidByPort(port string) (ret string) {
}
return
}
+
+func initPandoc() {
+ if ContainerStd != Container {
+ return
+ }
+
+ pandocDir := filepath.Join(TempDir, "pandoc")
+ if gulu.OS.IsWindows() {
+ PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe")
+ } else if gulu.OS.IsDarwin() || gulu.OS.IsLinux() {
+ PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
+ }
+ pandocVer := getPandocVer(PandocBinPath)
+ if "" != pandocVer {
+ logging.LogInfof("pandoc [ver=%s, bin=%s]", pandocVer, PandocBinPath)
+ return
+ }
+
+ pandocZip := filepath.Join(WorkingDir, "pandoc.zip")
+ if "dev" == Mode {
+ if gulu.OS.IsWindows() {
+ pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-windows-amd64.zip")
+ } else if gulu.OS.IsDarwin() {
+ pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-darwin-amd64.zip")
+ } else if gulu.OS.IsLinux() {
+ pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-amd64.zip")
+ }
+ }
+ if err := gulu.Zip.Unzip(pandocZip, pandocDir); nil != err {
+ logging.LogErrorf("unzip pandoc failed: %s", err)
+ return
+ }
+
+ if gulu.OS.IsDarwin() || gulu.OS.IsLinux() {
+ exec.Command("chmod", "+x", PandocBinPath).CombinedOutput()
+ }
+ pandocVer = getPandocVer(PandocBinPath)
+ logging.LogInfof("initialized pandoc [ver=%s, bin=%s]", pandocVer, PandocBinPath)
+}
+
+func getPandocVer(binPath string) (ret string) {
+ if "" == binPath {
+ return
+ }
+
+ cmd := exec.Command(binPath, "--version")
+ CmdAttr(cmd)
+ data, err := cmd.CombinedOutput()
+ if nil == err && strings.HasPrefix(string(data), "pandoc") {
+ parts := bytes.Split(data, []byte("\n"))
+ if 0 < len(parts) {
+ ret = strings.TrimPrefix(string(parts[0]), "pandoc")
+ ret = strings.ReplaceAll(ret, ".exe", "")
+ ret = strings.TrimSpace(ret)
+ }
+ return
+ }
+ return
+}
+
+func IsValidPandocBin(binPath string) bool {
+ if "" == binPath {
+ return false
+ }
+
+ cmd := exec.Command(binPath, "--version")
+ CmdAttr(cmd)
+ data, err := cmd.CombinedOutput()
+ if nil == err && strings.HasPrefix(string(data), "pandoc") {
+ return true
+ }
+ return false
+}