An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve handling of assets when exporting to Word .docx format https://github.com/siyuan-note/siyuan/issues/15253
Daniel0bc96f4d75a4
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 8827d1991f..5ea3edad17 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -1212,7 +1212,7 @@ func getQueryEmbedNodesAssetsLinkDests(node *ast.Node) (ret []string) {return}-func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {+func getAssetsLinkDests(node *ast.Node, includeServePath bool) (ret []string) {ret = []string{}ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {if n.IsBlock() {@@ -1222,7 +1222,7 @@ func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {k := kv[0]if strings.HasPrefix(k, "custom-data-assets") {dest := kv[1]- if "" == dest || !util.IsAssetLinkDest([]byte(dest), includePublic) {+ if "" == dest || !util.IsAssetLinkDest([]byte(dest), includeServePath) {continue}ret = append(ret, dest)@@ -1238,21 +1238,21 @@ func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {}if ast.NodeLinkDest == n.Type {- if !util.IsAssetLinkDest(n.Tokens, includePublic) {+ if !util.IsAssetLinkDest(n.Tokens, includeServePath) {return ast.WalkContinue}dest := strings.TrimSpace(string(n.Tokens))ret = append(ret, dest)} else if n.IsTextMarkType("a") {- if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkAHref), includePublic) {+ if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkAHref), includeServePath) {return ast.WalkContinue}dest := strings.TrimSpace(n.TextMarkAHref)ret = append(ret, dest)} else if n.IsTextMarkType("file-annotation-ref") {- if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID), includePublic) {+ if !util.IsAssetLinkDest(gulu.Str.ToBytes(n.TextMarkFileAnnotationRefID), includeServePath) {return ast.WalkContinue}@@ -1278,7 +1278,7 @@ func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {for _, asset := range value.MAsset {dest := asset.Content- if !util.IsAssetLinkDest([]byte(dest), includePublic) {+ if !util.IsAssetLinkDest([]byte(dest), includeServePath) {continue}ret = append(ret, strings.TrimSpace(dest))@@ -1288,7 +1288,7 @@ func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {for _, value := range keyValues.Values {if nil != value.URL {dest := value.URL.Content- if !util.IsAssetLinkDest([]byte(dest), includePublic) {+ if !util.IsAssetLinkDest([]byte(dest), includeServePath) {continue}ret = append(ret, strings.TrimSpace(dest))@@ -1303,13 +1303,13 @@ func getAssetsLinkDests(node *ast.Node, includePublic bool) (ret []string) {// 兼容两种属性名 custom-data-assets 和 data-assets https://github.com/siyuan-note/siyuan/issues/4122#issuecomment-1154796568dataAssets = n.IALAttr("data-assets")}- if !util.IsAssetLinkDest([]byte(dataAssets), includePublic) {+ if !util.IsAssetLinkDest([]byte(dataAssets), includeServePath) {return ast.WalkContinue}ret = append(ret, dataAssets)} else { // HTMLBlock/InlineHTML/IFrame/Audio/Videodest := treenode.GetNodeSrcTokens(n)- if !util.IsAssetLinkDest([]byte(dest), includePublic) {+ if !util.IsAssetLinkDest([]byte(dest), includeServePath) {return ast.WalkContinue}ret = append(ret, dest)diff --git a/kernel/util/path.go b/kernel/util/path.goindex b11d3dcab8..ff3e560262 100644--- a/kernel/util/path.go+++ b/kernel/util/path.go@@ -316,8 +316,12 @@ func FilterSelfChildDocs(paths []string) (ret []string) {return}-func IsAssetLinkDest(dest []byte, includePublic bool) bool {- return bytes.HasPrefix(dest, []byte("assets/")) || (includePublic && bytes.HasPrefix(dest, []byte("public/")))+func IsAssetLinkDest(dest []byte, includeServePath bool) bool {+ return bytes.HasPrefix(dest, []byte("assets/")) ||+ (includeServePath && (bytes.HasPrefix(dest, []byte("emojis/")) ||+ bytes.HasPrefix(dest, []byte("plugins/")) ||+ bytes.HasPrefix(dest, []byte("public/")) ||+ bytes.HasPrefix(dest, []byte("widgets/"))))}var (