mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-02 21:51:49 +01:00
🎨 Supports setting Pandoc parameters for export docx https://github.com/siyuan-note/siyuan/issues/16845 https://github.com/siyuan-note/siyuan/issues/14970#issuecomment-3793004593
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
2659950350
commit
18761d43a3
3 changed files with 4 additions and 34 deletions
|
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
|
||||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
|
||||
github.com/88250/gulu v1.2.3-0.20251208021445-f93f2666eaac
|
||||
github.com/88250/gulu v1.2.3-0.20260124101918-98654a7ca98a
|
||||
github.com/88250/lute v1.7.7-0.20260119115611-b18a050e4eae
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7 h1:MafIFwSS0x6A4
|
|||
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7/go.mod h1:HrKCCTin3YNDSLBD02K0AOljjV6eNwc3/zyEI+xyV1I=
|
||||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceTVVqrYaDlLio2QSKbXMUmAZPbzCwT5eNCw=
|
||||
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20251208021445-f93f2666eaac h1:EC80pY8zyR0gbL8ZLIBB4IPG/ia3ZHScrR/xt8zU8qU=
|
||||
github.com/88250/gulu v1.2.3-0.20251208021445-f93f2666eaac/go.mod h1:IQ5dXW9CjVmx6B7OfK1Y4ZBKTPMe9q1AkVoLGGzRbS8=
|
||||
github.com/88250/gulu v1.2.3-0.20260124101918-98654a7ca98a h1:s86WMolaqommXG1k2vXg9Gf1iXvgtHSdeD0eeJTQVR8=
|
||||
github.com/88250/gulu v1.2.3-0.20260124101918-98654a7ca98a/go.mod h1:D+Db16m0N7r9MLZCMcj1a0ZsEGQAxDZkadOn79Gh0vI=
|
||||
github.com/88250/lute v1.7.7-0.20260119115611-b18a050e4eae h1:XVdbxiLwEJQbTzkRmCNOcfshEPA060MvXvEk5j/ZPcg=
|
||||
github.com/88250/lute v1.7.7-0.20260119115611-b18a050e4eae/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20250424122812-f10e8d9d8d46 h1:Bq1JsDfVbHKUxNL/B2JXd8cC/1h6aFjrlXpGycnh0Hk=
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
windows "golang.org/x/sys/windows"
|
||||
ianaindex "golang.org/x/text/encoding/ianaindex"
|
||||
)
|
||||
|
||||
func ExportCodeBlock(blockID string) (filePath string, err error) {
|
||||
|
|
@ -803,7 +801,7 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
|
|||
pandoc.Stdin = bytes.NewBufferString(content)
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if err != nil {
|
||||
msg := DecodeCmdOutput(output)
|
||||
msg := gulu.DecodeCmdOutput(output)
|
||||
logging.LogErrorf("export docx failed: %s", msg)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(14), msg))
|
||||
return
|
||||
|
|
@ -827,34 +825,6 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
|
|||
return
|
||||
}
|
||||
|
||||
func DecodeCmdOutput(output []byte) string {
|
||||
if !gulu.OS.IsWindows() {
|
||||
return string(output)
|
||||
}
|
||||
|
||||
// 1. 检查是否已经是 UTF-8
|
||||
if utf8.Valid(output) {
|
||||
return string(output)
|
||||
}
|
||||
|
||||
// 2. 获取当前系统 ANSI 代码页 (例如: 950 是 Big5, 932 是日文 Shift-JIS)
|
||||
acp := windows.GetACP()
|
||||
|
||||
// 3. 将代码页 ID 转为编码格式 (例如 "CP950")
|
||||
encodingName := fmt.Sprintf("CP%d", acp)
|
||||
e, err := ianaindex.MIB.Encoding(encodingName)
|
||||
if err != nil {
|
||||
return string(output) // 找不到对应编码则返回原始字节转换
|
||||
}
|
||||
|
||||
// 4. 执行解码
|
||||
decoded, err := e.NewDecoder().Bytes(output)
|
||||
if err != nil {
|
||||
return string(output)
|
||||
}
|
||||
return string(decoded)
|
||||
}
|
||||
|
||||
func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string) {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue