Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-09-26 09:38:27 +08:00
commit d87191b3a6
9 changed files with 101 additions and 13 deletions

File diff suppressed because one or more lines are too long

View file

@ -128,7 +128,7 @@ func html2BlockDOM(c *gin.Context) {
}
// 复制带超链接的图片无法保存到本地 https://github.com/siyuan-note/siyuan/issues/5993
parse.NestedInlines2FlattedSpans(tree)
parse.NestedInlines2FlattedSpans(tree, false)
renderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions)
output := renderer.Render()

View file

@ -89,7 +89,7 @@ func ParseJSON(jsonData []byte, options *parse.Options) (ret *parse.Tree, needFi
}
if needMigrate2Spec1 {
parse.NestedInlines2FlattedSpans(ret)
parse.NestedInlines2FlattedSpans(ret, false)
needFix = true
}
return

View file

@ -158,7 +158,7 @@ func prepareWriteTree(tree *parse.Tree) (data []byte, filePath string, err error
filePath = filepath.Join(util.DataDir, tree.Box, tree.Path)
if oldSpec := tree.Root.Spec; "" == oldSpec {
parse.NestedInlines2FlattedSpans(tree)
parse.NestedInlines2FlattedSpans(tree, false)
tree.Root.Spec = "1"
logging.LogInfof("migrated tree [%s] from spec [%s] to [%s]", filePath, oldSpec, tree.Root.Spec)
}
@ -199,7 +199,7 @@ func parseJSON2Tree(boxID, p string, jsonData []byte, luteEngine *lute.Lute) (re
filePath := filepath.Join(util.DataDir, ret.Box, ret.Path)
if oldSpec := ret.Root.Spec; "" == oldSpec {
parse.NestedInlines2FlattedSpans(ret)
parse.NestedInlines2FlattedSpans(ret, false)
ret.Root.Spec = "1"
needFix = true
logging.LogInfof("migrated tree [%s] from spec [%s] to [%s]", filePath, oldSpec, ret.Root.Spec)

View file

@ -8,7 +8,7 @@ require (
github.com/88250/css v0.1.2
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346
github.com/88250/lute v1.7.6-0.20230925081541-b99494256742
github.com/88250/lute v1.7.6-0.20230925134424-c4f269de7172
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20230727142813-c94579738c5b

View file

@ -61,8 +61,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346 h1:U0wZN6zuf+vUhzdHC6DbZE/bY5FUt3FuCwn/KgObV44=
github.com/88250/gulu v1.2.3-0.20230615033005-b519d6875346/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
github.com/88250/lute v1.7.6-0.20230925081541-b99494256742 h1:Yxg7G5oZzTDk195TIku9FBoL5hDQ3zswW6j/XRJ9BKA=
github.com/88250/lute v1.7.6-0.20230925081541-b99494256742/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/lute v1.7.6-0.20230925134424-c4f269de7172 h1:wZagZwg4ez/uaabhjCVuHajOPB5R789NfAMOE4HCjcE=
github.com/88250/lute v1.7.6-0.20230925134424-c4f269de7172/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -529,6 +529,19 @@ func (tx *Transaction) removeAttributeViewBlock(operation *Operation) (err error
}
delete(attrs, NodeAttrNamePrefixAvKey+operation.AvID+"-"+values.KeyID)
node.RemoveIALAttr(NodeAttrNamePrefixAvKey + operation.AvID + "-" + values.KeyID)
if avs := attrs[NodeAttrNameAvs]; "" != avs {
avIDs := strings.Split(avs, ",")
avIDs = gulu.Str.RemoveElem(avIDs, operation.AvID)
if 0 == len(avIDs) {
delete(attrs, NodeAttrNameAvs)
node.RemoveIALAttr(NodeAttrNameAvs)
} else {
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
node.SetIALAttr(NodeAttrNameAvs, strings.Join(avIDs, ","))
}
}
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
return
}

View file

@ -1357,6 +1357,32 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
}
}
// 导出数据库 Attribute View export https://github.com/siyuan-note/siyuan/issues/8710
exportStorageAvDir := filepath.Join(exportFolder, "storage", "av")
for _, tree := range trees {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if ast.NodeAttributeView != n.Type {
return ast.WalkContinue
}
avID := n.AttributeViewID
avJSONPath := av.GetAttributeViewDataPath(avID)
if !gulu.File.IsExist(avJSONPath) {
return ast.WalkContinue
}
if copyErr := filelock.Copy(avJSONPath, filepath.Join(exportStorageAvDir, avID+".json")); nil != copyErr {
logging.LogErrorf("copy av json failed: %s", copyErr)
}
return ast.WalkContinue
})
}
// 导出自定义排序
sortPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
fullSortIDs := map[string]int{}

View file

@ -123,6 +123,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
luteEngine := util.NewLute()
blockIDs := map[string]string{}
avBlockIDs := map[string]string{}
trees := map[string]*parse.Tree{}
// 重新生成块 ID
@ -146,9 +147,19 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
if "" != n.ID {
newNodeID := ast.NewNodeID()
blockIDs[n.ID] = newNodeID
oldNodeID := n.ID
n.ID = newNodeID
n.SetIALAttr("id", newNodeID)
// 重新指向数据库属性值
ial := parse.IAL2Map(n.KramdownIAL)
for k, v := range ial {
if strings.HasPrefix(k, NodeAttrNamePrefixAvKey) {
v = strings.ReplaceAll(v, oldNodeID, newNodeID)
n.SetIALAttr(k, v)
avBlockIDs[oldNodeID] = newNodeID
}
}
}
return ast.WalkContinue
})
@ -187,11 +198,49 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
})
}
// 将关联的数据库文件移动到 data/storage/av/ 下
storageAvDir := filepath.Join(unzipRootPath, "storage", "av")
if gulu.File.IsExist(storageAvDir) {
// 将数据库文件中的块 ID 替换为新的块 ID
filepath.Walk(storageAvDir, func(path string, info fs.FileInfo, err error) error {
if !strings.HasSuffix(path, ".json") || !ast.IsNodeIDPattern(strings.TrimSuffix(info.Name(), ".json")) {
return nil
}
data, readErr := os.ReadFile(path)
if nil != readErr {
logging.LogErrorf("read av file [%s] failed: %s", path, readErr)
return nil
}
var newData []byte
newData = data
for oldID, newID := range avBlockIDs {
newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
}
if !bytes.Equal(data, newData) {
if writeErr := os.WriteFile(path, newData, 0644); nil != writeErr {
logging.LogErrorf("write av file [%s] failed: %s", path, writeErr)
return nil
}
}
return nil
})
targetStorageAvDir := filepath.Join(util.DataDir, "storage", "av")
if copyErr := filelock.Copy(storageAvDir, targetStorageAvDir); nil != copyErr {
logging.LogErrorf("copy storage av dir from [%s] to [%s] failed: %s", storageAvDir, targetStorageAvDir, copyErr)
}
if removeErr := os.RemoveAll(storageAvDir); nil != removeErr {
logging.LogErrorf("remove temp storage av dir failed: %s", removeErr)
}
}
// 写回 .sy
for _, tree := range trees {
syPath := filepath.Join(unzipRootPath, tree.Path)
if "" == tree.Root.Spec {
parse.NestedInlines2FlattedSpans(tree)
parse.NestedInlines2FlattedSpans(tree, false)
tree.Root.Spec = "1"
}
renderer := render.NewJSONRenderer(tree, luteEngine.RenderOptions)
@ -751,7 +800,7 @@ func parseStdMd(markdown []byte) (ret *parse.Tree) {
}
genTreeID(ret)
imgHtmlBlock2InlineImg(ret)
parse.NestedInlines2FlattedSpansHybrid(ret)
parse.NestedInlines2FlattedSpansHybrid(ret, false)
return
}
@ -1070,7 +1119,7 @@ func buildBlockRefInText() {
}
t := parse.Inline("", n.Tokens, lute.ParseOptions) // 使用行级解析
parse.NestedInlines2FlattedSpans(t)
parse.NestedInlines2FlattedSpans(t, false)
var children []*ast.Node
for c := t.Root.FirstChild.FirstChild; nil != c; c = c.Next {
children = append(children, c)