🎨 Add more file formats supporting snapshots comparing https://github.com/siyuan-note/siyuan/issues/8438

This commit is contained in:
Daniel 2023-06-03 17:05:33 +08:00
parent 7ebc8f0459
commit e50a9b4e11
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 13 additions and 13 deletions

View file

@ -75,7 +75,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
textElement.previousElementSibling.classList.remove("fn__none"); textElement.previousElementSibling.classList.remove("fn__none");
textElement.classList.add("fn__none"); textElement.classList.add("fn__none");
leftElement.lastElementChild.classList.add("fn__none"); leftElement.lastElementChild.classList.add("fn__none");
} else if (response.data.isLargeDoc) { } else if (response.data.isProtyleDoc) {
textElement.value = response.data.content; textElement.value = response.data.content;
textElement.classList.remove("fn__none"); textElement.classList.remove("fn__none");
leftElement.lastElementChild.classList.add("fn__none"); leftElement.lastElementChild.classList.add("fn__none");
@ -103,7 +103,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
textElement.previousElementSibling.classList.remove("fn__none"); textElement.previousElementSibling.classList.remove("fn__none");
textElement.classList.add("fn__none"); textElement.classList.add("fn__none");
rightElement.lastElementChild.classList.add("fn__none"); rightElement.lastElementChild.classList.add("fn__none");
} else if (response.data.isLargeDoc) { } else if (response.data.isProtyleDoc) {
textElement.value = response.data.content; textElement.value = response.data.content;
textElement.classList.remove("fn__none"); textElement.classList.remove("fn__none");
rightElement.lastElementChild.classList.add("fn__none"); rightElement.lastElementChild.classList.add("fn__none");

View file

@ -36,7 +36,7 @@ func openRepoSnapshotDoc(c *gin.Context) {
} }
id := arg["id"].(string) id := arg["id"].(string)
content, isLargeDoc, updated, err := model.OpenRepoSnapshotDoc(id) content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()
@ -45,7 +45,7 @@ func openRepoSnapshotDoc(c *gin.Context) {
ret.Data = map[string]interface{}{ ret.Data = map[string]interface{}{
"content": content, "content": content,
"isLargeDoc": isLargeDoc, "isProtyleDoc": isProtyleDoc,
"updated": updated, "updated": updated,
} }
} }

View file

@ -71,7 +71,7 @@ type TypeCount struct {
Count int `json:"count"` Count int `json:"count"`
} }
func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, updated int64, err error) { func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, updated int64, err error) {
if 1 > len(Conf.Repo.Key) { if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26)) err = errors.New(Conf.Language(26))
return return
@ -97,13 +97,13 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
if strings.HasSuffix(file.Path, ".sy") { if strings.HasSuffix(file.Path, ".sy") {
luteEngine := NewLute() luteEngine := NewLute()
var snapshotTree *parse.Tree var snapshotTree *parse.Tree
isLargeDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine) isProtyleDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
if nil != err { if nil != err {
logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID) logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID)
return return
} }
if !isLargeDoc { if !isProtyleDoc {
renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}} renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}}
var unlinks []*ast.Node var unlinks []*ast.Node
@ -133,7 +133,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
} }
luteEngine.RenderOptions.ProtyleContenteditable = false luteEngine.RenderOptions.ProtyleContenteditable = false
if isLargeDoc { if isProtyleDoc {
util.PushMsg(Conf.Language(36), 5000) util.PushMsg(Conf.Language(36), 5000)
formatRenderer := render.NewFormatRenderer(snapshotTree, luteEngine.RenderOptions) formatRenderer := render.NewFormatRenderer(snapshotTree, luteEngine.RenderOptions)
content = gulu.Str.FromBytes(formatRenderer.Render()) content = gulu.Str.FromBytes(formatRenderer.Render())
@ -141,7 +141,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
content = luteEngine.Tree2BlockDOM(snapshotTree, luteEngine.RenderOptions) content = luteEngine.Tree2BlockDOM(snapshotTree, luteEngine.RenderOptions)
} }
} else { } else {
isLargeDoc = true isProtyleDoc = true
if strings.HasSuffix(file.Path, ".json") { if strings.HasSuffix(file.Path, ".json") {
content = gulu.Str.FromBytes(data) content = gulu.Str.FromBytes(data)
} else { } else {
@ -306,8 +306,8 @@ func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lut
return return
} }
func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isLargeDoc bool, tree *parse.Tree, err error) { func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isProtyleDoc bool, tree *parse.Tree, err error) {
isLargeDoc = 1024*1024*1 <= len(data) isProtyleDoc = 1024*1024*1 <= len(data)
tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions) tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
if nil != err { if nil != err {
return return