mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-18 13:08:06 +01:00
🐛 Fix pandoc export
This commit is contained in:
parent
ca01112462
commit
b2c0f3ea1f
3 changed files with 18 additions and 17 deletions
|
|
@ -36,7 +36,7 @@ func ConvertPandoc(args ...string) (err error) {
|
|||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "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)
|
||||
return
|
||||
|
|
@ -50,31 +50,38 @@ func ConvertPandoc(args ...string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func Pandoc(from, to, o, content string) (ret string, err error) {
|
||||
func Pandoc(from, to, o, content string) (err error) {
|
||||
if "" == from || "" == to || "md" == to {
|
||||
ret = content
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
tmpPath := filepath.Join(dir, gulu.Rand.String(7))
|
||||
if err = os.WriteFile(tmpPath, []byte(content), 0644); nil != err {
|
||||
logging.LogErrorf("write file failed: [%s]", err)
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
tmpPath,
|
||||
"--from", from,
|
||||
"--to", to,
|
||||
"--resource-path", filepath.Dir(o),
|
||||
"-s",
|
||||
}
|
||||
|
||||
if "" != o {
|
||||
args = append(args, "-o", o)
|
||||
"-o", o,
|
||||
}
|
||||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
pandoc.Stdin = bytes.NewBufferString(content)
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("pandoc convert output [%s], error [%s]", string(output), err)
|
||||
return
|
||||
}
|
||||
ret = string(output)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue