Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-24 20:17:05 +08:00
parent 2659950350
commit 18761d43a3
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 4 additions and 34 deletions

View file

@ -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 {