🎨 Improve handling of assets when exporting to Word .docx format https://github.com/siyuan-note/siyuan/issues/15253

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-12 11:56:16 +08:00
parent 2e9ef1e028
commit 4bc9d9496e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 29 additions and 30 deletions

View file

@ -716,7 +716,7 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
content = strings.ReplaceAll(content, " \n", "<br>\n")
tmpDocxPath := filepath.Join(tmpDir, name+".docx")
args := []string{ // pandoc -f html --resource-path=请从这里开始 请从这里开始\index.html -o test.docx
args := []string{
"-f", "html+tex_math_dollars",
"--resource-path", tmpDir,
"-o", tmpDocxPath,
@ -796,17 +796,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
}
if docx {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if ast.NodeLinkDest == n.Type {
if bytes.HasPrefix(n.Tokens, []byte("file://")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"), []byte("/"))
if !bytes.HasPrefix(n.Tokens, []byte("file:///")) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("file://"), []byte("file:///"))
}
}
}
return ast.WalkContinue
})
netAssets2LocalAssets0(tree, true, "", filepath.Join(savePath, "assets"), false)
}
assets := getAssetsLinkDests(tree.Root, docx)
@ -814,7 +804,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
if !util.IsAssetLinkDest([]byte(asset), docx) {
continue
}
if strings.Contains(asset, "?") {
asset = asset[:strings.LastIndex(asset, "?")]
}