mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 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:
parent
99246f24d3
commit
3b914cc9d3
1 changed files with 12 additions and 4 deletions
|
|
@ -2162,11 +2162,19 @@ func exportMarkdownContent0(id string, tree *parse.Tree, cloudAssetsBase string,
|
||||||
href = "#" + defID
|
href = "#" + defID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newHref := strings.TrimPrefix(href, currentDocDir)
|
|
||||||
if !strings.HasPrefix(newHref, ".md") {
|
sameDir := path.Dir(href) == currentDocDir
|
||||||
href = newHref
|
|
||||||
}
|
|
||||||
href = util.FilterFilePath(href)
|
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 := &ast.Node{Type: ast.NodeTextMark, TextMarkType: "a", TextMarkTextContent: linkText, TextMarkAHref: href}
|
||||||
blockRefLink.KramdownIAL = n.KramdownIAL
|
blockRefLink.KramdownIAL = n.KramdownIAL
|
||||||
n.InsertBefore(blockRefLink)
|
n.InsertBefore(blockRefLink)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue