mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 01:21:14 +08:00
🎨 Improve importing Markdown https://github.com/siyuan-note/siyuan/issues/13245
This commit is contained in:
parent
84fc7092dd
commit
535db65bf6
@ -695,6 +695,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
|
|
||||||
hPathsIDs := map[string]string{}
|
hPathsIDs := map[string]string{}
|
||||||
idPaths := map[string]string{}
|
idPaths := map[string]string{}
|
||||||
|
moveIDs := map[string]string{}
|
||||||
|
|
||||||
if gulu.File.IsDir(localPath) { // 导入文件夹
|
if gulu.File.IsDir(localPath) { // 导入文件夹
|
||||||
// 收集所有资源文件
|
// 收集所有资源文件
|
||||||
@ -793,6 +794,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if "" != yfmRootID {
|
if "" != yfmRootID {
|
||||||
|
moveIDs[id] = yfmRootID
|
||||||
id = yfmRootID
|
id = yfmRootID
|
||||||
}
|
}
|
||||||
if "" != yfmTitle {
|
if "" != yfmTitle {
|
||||||
@ -999,6 +1001,13 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 0 < len(importTrees) {
|
if 0 < len(importTrees) {
|
||||||
|
for id, newID := range moveIDs {
|
||||||
|
for _, importTree := range importTrees {
|
||||||
|
importTree.ID = strings.ReplaceAll(importTree.ID, id, newID)
|
||||||
|
importTree.Path = strings.ReplaceAll(importTree.Path, id, newID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initSearchLinks()
|
initSearchLinks()
|
||||||
convertWikiLinksAndTags()
|
convertWikiLinksAndTags()
|
||||||
buildBlockRefInText()
|
buildBlockRefInText()
|
||||||
@ -1184,16 +1193,6 @@ func imgHtmlBlock2InlineImg(tree *parse.Tree) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reassignIDUpdated(tree *parse.Tree, rootID, updated string) {
|
func reassignIDUpdated(tree *parse.Tree, rootID, updated string) {
|
||||||
var blockCount int
|
|
||||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
if !entering || "" == n.ID {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
blockCount++
|
|
||||||
return ast.WalkContinue
|
|
||||||
})
|
|
||||||
|
|
||||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || "" == n.ID {
|
if !entering || "" == n.ID {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
@ -1207,8 +1206,10 @@ func reassignIDUpdated(tree *parse.Tree, rootID, updated string) {
|
|||||||
n.SetIALAttr("id", n.ID)
|
n.SetIALAttr("id", n.ID)
|
||||||
if "" != updated {
|
if "" != updated {
|
||||||
n.SetIALAttr("updated", updated)
|
n.SetIALAttr("updated", updated)
|
||||||
n.ID = updated + "-" + gulu.Rand.String(7)
|
if "" == rootID {
|
||||||
n.SetIALAttr("id", n.ID)
|
n.ID = updated + "-" + gulu.Rand.String(7)
|
||||||
|
n.SetIALAttr("id", n.ID)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
n.SetIALAttr("updated", util.TimeFromID(n.ID))
|
n.SetIALAttr("updated", util.TimeFromID(n.ID))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user