mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-28 11:16:09 +01:00
🎨 Improve export to Word .docx format https://github.com/siyuan-note/siyuan/issues/14970
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
53e85a46bb
commit
cfcf695fb4
2 changed files with 19 additions and 23 deletions
|
|
@ -1272,7 +1272,9 @@ func subscribeConfEvents() {
|
|||
params += " \"" + util.PandocTemplatePath + "\""
|
||||
Conf.Export.PandocParams = strings.TrimSpace(params)
|
||||
}
|
||||
|
||||
|
||||
logging.LogInfof("pandoc params set to [%s]", Conf.Export.PandocParams)
|
||||
logging.LogInfof("pandoc template [%s], color filter [%s]", util.PandocTemplatePath, util.PandocColorFilterPath)
|
||||
Conf.Save()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func InitPandoc() {
|
|||
return
|
||||
}
|
||||
|
||||
pandocDir := filepath.Join(TempDir, "pandoc")
|
||||
tempPandocDir := filepath.Join(TempDir, "pandoc")
|
||||
|
||||
if confPath := filepath.Join(ConfDir, "conf.json"); gulu.File.IsExist(confPath) {
|
||||
// Workspace built-in Pandoc is no longer initialized after customizing Pandoc path https://github.com/siyuan-note/siyuan/issues/8377
|
||||
|
|
@ -119,7 +119,7 @@ func InitPandoc() {
|
|||
conf := map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &conf); err == nil && nil != conf["export"] {
|
||||
export := conf["export"].(map[string]interface{})
|
||||
if customPandocBinPath := export["pandocBin"].(string); !strings.HasPrefix(customPandocBinPath, pandocDir) {
|
||||
if customPandocBinPath := export["pandocBin"].(string); !strings.HasPrefix(customPandocBinPath, tempPandocDir) {
|
||||
if pandocVer := getPandocVer(customPandocBinPath); "" != pandocVer {
|
||||
PandocBinPath = customPandocBinPath
|
||||
logging.LogInfof("custom pandoc [ver=%s, bin=%s]", pandocVer, PandocBinPath)
|
||||
|
|
@ -130,24 +130,18 @@ func InitPandoc() {
|
|||
}
|
||||
}
|
||||
|
||||
PandocTemplatePath = filepath.Join(pandocDir, "pandoc-resources", "pandoc-template.docx")
|
||||
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc-template.docx")
|
||||
if !gulu.File.IsExist(PandocTemplatePath) {
|
||||
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc-template.docx")
|
||||
if "dev" == Mode || !gulu.File.IsExist(PandocTemplatePath) {
|
||||
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc-template.docx")
|
||||
}
|
||||
PandocTemplatePath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc-template.docx")
|
||||
}
|
||||
if !gulu.File.IsExist(PandocTemplatePath) {
|
||||
PandocTemplatePath = ""
|
||||
logging.LogWarnf("pandoc template file [%s] not found", PandocTemplatePath)
|
||||
}
|
||||
|
||||
PandocColorFilterPath = filepath.Join(pandocDir, "pandoc-resources", "pandoc_color_filter.lua")
|
||||
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc_color_filter.lua")
|
||||
if !gulu.File.IsExist(PandocColorFilterPath) {
|
||||
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc-resources", "pandoc_color_filter.lua")
|
||||
if "dev" == Mode || !gulu.File.IsExist(PandocColorFilterPath) {
|
||||
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc_color_filter.lua")
|
||||
}
|
||||
PandocColorFilterPath = filepath.Join(WorkingDir, "pandoc", "pandoc-resources", "pandoc_color_filter.lua")
|
||||
}
|
||||
if !gulu.File.IsExist(PandocColorFilterPath) {
|
||||
PandocColorFilterPath = ""
|
||||
|
|
@ -158,13 +152,13 @@ func InitPandoc() {
|
|||
|
||||
if gulu.OS.IsWindows() {
|
||||
if "amd64" == runtime.GOARCH {
|
||||
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe")
|
||||
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc.exe")
|
||||
}
|
||||
} else if gulu.OS.IsDarwin() {
|
||||
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
|
||||
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc")
|
||||
} else if gulu.OS.IsLinux() {
|
||||
if "amd64" == runtime.GOARCH {
|
||||
PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc")
|
||||
PandocBinPath = filepath.Join(tempPandocDir, "bin", "pandoc")
|
||||
}
|
||||
}
|
||||
pandocVer := getPandocVer(PandocBinPath)
|
||||
|
|
@ -174,22 +168,22 @@ func InitPandoc() {
|
|||
}
|
||||
|
||||
pandocZip := filepath.Join(WorkingDir, "pandoc.zip")
|
||||
if "dev" == Mode || !gulu.File.IsExist(pandocZip) {
|
||||
if !gulu.File.IsExist(pandocZip) {
|
||||
if gulu.OS.IsWindows() {
|
||||
if "amd64" == runtime.GOARCH {
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-windows-amd64.zip")
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-windows-amd64.zip")
|
||||
}
|
||||
} else if gulu.OS.IsDarwin() {
|
||||
if "amd64" == runtime.GOARCH {
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-darwin-amd64.zip")
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-amd64.zip")
|
||||
} else if "arm64" == runtime.GOARCH {
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-darwin-arm64.zip")
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-arm64.zip")
|
||||
}
|
||||
} else if gulu.OS.IsLinux() {
|
||||
if "amd64" == runtime.GOARCH {
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-amd64.zip")
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-amd64.zip")
|
||||
} else if "arm64" == runtime.GOARCH {
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc/pandoc-linux-arm64.zip")
|
||||
pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-arm64.zip")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -200,7 +194,7 @@ func InitPandoc() {
|
|||
return
|
||||
}
|
||||
|
||||
if err := gulu.Zip.Unzip(pandocZip, pandocDir); err != nil {
|
||||
if err := gulu.Zip.Unzip(pandocZip, tempPandocDir); err != nil {
|
||||
logging.LogErrorf("unzip pandoc failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue