🎨 Built-in Pandoc export .docx template https://github.com/siyuan-note/siyuan/issues/16861

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-18 20:50:41 +08:00
parent 1f02650b38
commit 1012d8b486
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
11 changed files with 44 additions and 4 deletions

View file

@ -1262,6 +1262,14 @@ func subscribeConfEvents() {
eventbus.Subscribe(util.EvtConfPandocInitialized, func() {
logging.LogInfof("pandoc initialized, set pandoc bin to [%s]", util.PandocBinPath)
Conf.Export.PandocBin = util.PandocBinPath
params := util.RemoveInvalid(Conf.Export.PandocParams)
if !strings.Contains(params, "--reference-doc") && "" != util.PandocTemplatePath {
params += " --reference-doc"
params += " \"" + util.PandocTemplatePath + "\""
Conf.Export.PandocParams = strings.TrimSpace(params)
}
Conf.Save()
})
}

View file

@ -45,6 +45,7 @@ import (
"github.com/emirpasic/gods/sets/hashset"
"github.com/emirpasic/gods/stacks/linkedliststack"
"github.com/imroc/req/v3"
shellquote "github.com/kballard/go-shellquote"
"github.com/pdfcpu/pdfcpu/pkg/api"
"github.com/pdfcpu/pdfcpu/pkg/font"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
@ -773,7 +774,12 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
params := util.RemoveInvalid(Conf.Export.PandocParams)
if "" != params {
args = append(args, strings.Split(params, " ")...)
customArgs, parseErr := shellquote.Split(params)
if nil != parseErr {
logging.LogErrorf("parse pandoc custom params [%s] failed: %s", params, parseErr)
} else {
args = append(args, customArgs...)
}
}
pandoc := exec.Command(Conf.Export.PandocBin, args...)