🎨 Improve exporting markdown block ref relative path https://github.com/siyuan-note/siyuan/issues/16042

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-10-11 18:08:35 +08:00
parent 99246f24d3
commit 3b914cc9d3
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -2162,11 +2162,19 @@ func exportMarkdownContent0(id string, tree *parse.Tree, cloudAssetsBase string,
href = "#" + defID
}
}
newHref := strings.TrimPrefix(href, currentDocDir)
if !strings.HasPrefix(newHref, ".md") {
href = newHref
}
sameDir := path.Dir(href) == currentDocDir
href = util.FilterFilePath(href)
if !sameDir {
var relErr error
href, relErr = filepath.Rel(currentDocDir, href)
if nil != relErr {
logging.LogWarnf("get relative path from [%s] to [%s] failed: %s", currentDocDir, href, relErr)
}
href = filepath.ToSlash(href)
} else {
href = strings.TrimPrefix(href, currentDocDir+"/")
}
blockRefLink := &ast.Node{Type: ast.NodeTextMark, TextMarkType: "a", TextMarkTextContent: linkText, TextMarkAHref: href}
blockRefLink.KramdownIAL = n.KramdownIAL
n.InsertBefore(blockRefLink)