mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
🧑💻 Improve kernel API /api/convert/pandoc Fix https://github.com/siyuan-note/siyuan/issues/8619
This commit is contained in:
parent
b3d3048924
commit
fc818c6511
4 changed files with 46 additions and 24 deletions
|
|
@ -29,24 +29,28 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func ConvertPandoc(args ...string) (err error) {
|
||||
func ConvertPandoc(dir string, args ...string) (path string, err error) {
|
||||
if "" == PandocBinPath || ContainerStd != Container {
|
||||
return errors.New("not found executable pandoc")
|
||||
err = errors.New("not found executable pandoc")
|
||||
return
|
||||
}
|
||||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc", gulu.Rand.String(7))
|
||||
if err = os.MkdirAll(dir, 0755); nil != err {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
|
||||
path = filepath.Join("temp", "convert", "pandoc", dir)
|
||||
absPath := filepath.Join(WorkspaceDir, path)
|
||||
if err = os.MkdirAll(absPath, 0755); nil != err {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", absPath, err)
|
||||
return
|
||||
}
|
||||
pandoc.Dir = dir
|
||||
pandoc.Dir = absPath
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("pandoc convert output [%s]", string(output))
|
||||
err = errors.Join(err, errors.New(string(output)))
|
||||
logging.LogErrorf("pandoc convert output failed: %s", err)
|
||||
return
|
||||
}
|
||||
path = "/" + filepath.ToSlash(path)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue