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

This commit is contained in:
Liang Ding 2022-09-07 10:30:25 +08:00
parent ffa53aa4f1
commit d134045a60
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
13 changed files with 91 additions and 19 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -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
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}