mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-31 05:48:49 +01:00
🎨 Improve export of empty documents with subdocuments https://github.com/siyuan-note/siyuan/issues/15009
This commit is contained in:
parent
2e40a0a480
commit
19082e9d5f
1 changed files with 17 additions and 4 deletions
|
|
@ -1993,13 +1993,13 @@ func ExportMarkdownContent(id string, refMode, embedMode int, addYfm bool) (hPat
|
|||
return
|
||||
}
|
||||
|
||||
func exportMarkdownContent(id, ext string, exportRefMode int, defBlockIDs []string, singleFile bool, treeCache *map[string]*parse.Tree) (hPath, exportedMd string) {
|
||||
func exportMarkdownContent(id, ext string, exportRefMode int, defBlockIDs []string, singleFile bool, treeCache *map[string]*parse.Tree) (tree *parse.Tree, exportedMd string, isEmpty bool) {
|
||||
tree, err := loadTreeWithCache(id, treeCache)
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
|
||||
return
|
||||
}
|
||||
hPath = tree.HPath
|
||||
isEmpty = nil == tree.Root.FirstChild.FirstChild
|
||||
exportedMd = exportMarkdownContent0(tree, "", false,
|
||||
ext, exportRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
|
||||
Conf.Export.TagOpenMarker, Conf.Export.TagCloseMarker,
|
||||
|
|
@ -3128,7 +3128,11 @@ func exportPandocConvertZip(baseFolderName string, docPaths, defBlockIDs []strin
|
|||
luteEngine := util.NewLute()
|
||||
for i, p := range docPaths {
|
||||
id := util.GetTreeID(p)
|
||||
hPath, md := exportMarkdownContent(id, ext, exportRefMode, defBlockIDs, false, treeCache)
|
||||
tree, md, isEmpty := exportMarkdownContent(id, ext, exportRefMode, defBlockIDs, false, treeCache)
|
||||
if nil == tree {
|
||||
continue
|
||||
}
|
||||
hPath := tree.HPath
|
||||
dir, name = path.Split(hPath)
|
||||
dir = util.FilterFilePath(dir) // 导出文档时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/4590
|
||||
name = util.FilterFileName(name)
|
||||
|
|
@ -3147,8 +3151,17 @@ func exportPandocConvertZip(baseFolderName string, docPaths, defBlockIDs []strin
|
|||
continue
|
||||
}
|
||||
|
||||
if isEmpty {
|
||||
entries, readErr := os.ReadDir(filepath.Join(util.DataDir, tree.Box, strings.TrimSuffix(tree.Path, ".sy")))
|
||||
if nil == readErr && 0 < len(entries) {
|
||||
// 如果文档内容为空并且存在子文档则仅导出文件夹
|
||||
// Improve export of empty documents with subdocuments https://github.com/siyuan-note/siyuan/issues/15009
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 解析导出后的标准 Markdown,汇总 assets
|
||||
tree := parse.Parse("", gulu.Str.ToBytes(md), luteEngine.ParseOptions)
|
||||
tree = parse.Parse("", gulu.Str.ToBytes(md), luteEngine.ParseOptions)
|
||||
var assets []string
|
||||
assets = append(assets, assetsLinkDestsInTree(tree)...)
|
||||
for _, asset := range assets {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue