mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-02 05:31:47 +01:00
🎨 Provide API /api/convert/pandoc https://github.com/siyuan-note/siyuan/issues/8235
This commit is contained in:
parent
5c06d60f05
commit
0bfc2b5c64
5 changed files with 152 additions and 3 deletions
|
|
@ -18,6 +18,8 @@ package util
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -26,6 +28,27 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func ConvertPandoc(args ...string) (err error) {
|
||||
if "" == PandocBinPath || ContainerStd != Container {
|
||||
return errors.New("not found executable pandoc")
|
||||
}
|
||||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc")
|
||||
if err = os.MkdirAll(dir, 0755); nil != err {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
|
||||
return
|
||||
}
|
||||
pandoc.Dir = dir
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("pandoc convert output [%s]", string(output))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Pandoc(from, to, o, content string) (ret string, err error) {
|
||||
if "" == from || "" == to || "md" == to {
|
||||
ret = content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue