Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve exporting Markdown https://github.com/siyuan-note/siyuan/issues/13273

Daniel575869c546e4
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 8b58eb25af..47369a89e6 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1944,6 +1944,8 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
})
}
+ currentDocDir := path.Dir(tree.HPath)
+
var unlinks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
@@ -1979,12 +1981,14 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
var href string
bt := treenode.GetBlockTree(defID)
if nil != bt {
- href += strings.TrimPrefix(bt.HPath, "/") + ".md"
+ href += bt.HPath + ".md"
if "d" != bt.Type {
href += "#" + defID
}
}
+ href = strings.TrimPrefix(href, currentDocDir)
href = util.FilterFilePath(href)
+ href = strings.TrimPrefix(href, "/")
blockRefLink := &ast.Node{Type: ast.NodeTextMark, TextMarkType: "a", TextMarkTextContent: linkText, TextMarkAHref: href}
blockRefLink.KramdownIAL = n.KramdownIAL
n.InsertBefore(blockRefLink)