mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
145641cd06
commit
bb0ebefb1d
2 changed files with 58 additions and 4 deletions
|
|
@ -99,7 +99,7 @@ func Export2Liandi(id string) (err error) {
|
||||||
|
|
||||||
title := path.Base(tree.HPath)
|
title := path.Base(tree.HPath)
|
||||||
tags := tree.Root.IALAttr("tags")
|
tags := tree.Root.IALAttr("tags")
|
||||||
content := exportMarkdownContent0(tree, "https://b3logfile.com/siyuan/",
|
content := exportMarkdownContent0(tree, "https://b3logfile.com/siyuan/", true,
|
||||||
4, 1, 0,
|
4, 1, 0,
|
||||||
"#", "#",
|
"#", "#",
|
||||||
"", "",
|
"", "",
|
||||||
|
|
@ -729,7 +729,7 @@ func ExportStdMarkdown(id string) string {
|
||||||
if IsSubscriber() {
|
if IsSubscriber() {
|
||||||
cloudAssetsBase = "https://assets.b3logfile.com/siyuan/"
|
cloudAssetsBase = "https://assets.b3logfile.com/siyuan/"
|
||||||
}
|
}
|
||||||
return exportMarkdownContent0(tree, cloudAssetsBase,
|
return exportMarkdownContent0(tree, cloudAssetsBase, false,
|
||||||
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
||||||
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
||||||
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
||||||
|
|
@ -1167,7 +1167,7 @@ func exportMarkdownContent(id string) (hPath, exportedMd string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hPath = tree.HPath
|
hPath = tree.HPath
|
||||||
exportedMd = exportMarkdownContent0(tree, "",
|
exportedMd = exportMarkdownContent0(tree, "", false,
|
||||||
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
||||||
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
||||||
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
Conf.Export.BlockRefTextLeft, Conf.Export.BlockRefTextRight,
|
||||||
|
|
@ -1175,7 +1175,7 @@ func exportMarkdownContent(id string) (hPath, exportedMd string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string,
|
func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDestSpace2Underscore bool,
|
||||||
blockRefMode, blockEmbedMode, fileAnnotationRefMode int,
|
blockRefMode, blockEmbedMode, fileAnnotationRefMode int,
|
||||||
tagOpenMarker, tagCloseMarker string,
|
tagOpenMarker, tagCloseMarker string,
|
||||||
blockRefTextLeft, blockRefTextRight string,
|
blockRefTextLeft, blockRefTextRight string,
|
||||||
|
|
@ -1191,6 +1191,26 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string,
|
||||||
if "" != cloudAssetsBase {
|
if "" != cloudAssetsBase {
|
||||||
luteEngine.RenderOptions.LinkBase = cloudAssetsBase + Conf.User.UserId + "/"
|
luteEngine.RenderOptions.LinkBase = cloudAssetsBase + Conf.User.UserId + "/"
|
||||||
}
|
}
|
||||||
|
if assetsDestSpace2Underscore { // 上传到社区图床的资源文件会将空格转为下划线,所以这里也需要将文档内容做相应的转换
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
if ast.NodeLinkDest == n.Type {
|
||||||
|
if util.IsAssetLinkDest(n.Tokens) {
|
||||||
|
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(" "), []byte("_"))
|
||||||
|
}
|
||||||
|
} else if n.IsTextMarkType("a") {
|
||||||
|
href := n.TextMarkAHref
|
||||||
|
if util.IsAssetLinkDest([]byte(href)) {
|
||||||
|
n.TextMarkAHref = strings.ReplaceAll(href, " ", "_")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
|
renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
|
||||||
ret = gulu.Str.FromBytes(renderer.Render())
|
ret = gulu.Str.FromBytes(renderer.Render())
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,40 @@ func buildSpanFromNode(n *ast.Node, tree *parse.Tree, rootID, boxID, p string) (
|
||||||
IAL: treenode.IALStr(n),
|
IAL: treenode.IALStr(n),
|
||||||
}
|
}
|
||||||
spans = append(spans, span)
|
spans = append(spans, span)
|
||||||
|
|
||||||
|
if n.IsTextMarkType("a") {
|
||||||
|
dest := n.TextMarkAHref
|
||||||
|
if util.IsAssetLinkDest([]byte(dest)) {
|
||||||
|
var title string
|
||||||
|
if titleNode := n.ChildByType(ast.NodeLinkTitle); nil != titleNode {
|
||||||
|
title = gulu.Str.FromBytes(titleNode.Tokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hash string
|
||||||
|
var hashErr error
|
||||||
|
if lp := assetLocalPath(dest, boxLocalPath, docDirLocalPath); "" != lp {
|
||||||
|
if !gulu.File.IsDir(lp) {
|
||||||
|
hash, hashErr = util.GetEtag(lp)
|
||||||
|
if nil != hashErr {
|
||||||
|
logging.LogErrorf("calc asset [%s] hash failed: %s", lp, hashErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
name, _ := util.LastID(dest)
|
||||||
|
asset := &Asset{
|
||||||
|
ID: ast.NewNodeID(),
|
||||||
|
BlockID: parentBlock.ID,
|
||||||
|
RootID: rootID,
|
||||||
|
Box: boxID,
|
||||||
|
DocPath: p,
|
||||||
|
Path: dest,
|
||||||
|
Name: name,
|
||||||
|
Title: title,
|
||||||
|
Hash: hash,
|
||||||
|
}
|
||||||
|
assets = append(assets, asset)
|
||||||
|
}
|
||||||
|
}
|
||||||
walkStatus = ast.WalkSkipChildren
|
walkStatus = ast.WalkSkipChildren
|
||||||
return
|
return
|
||||||
case ast.NodeDocument:
|
case ast.NodeDocument:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue