mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Add more file formats supporting snapshots comparing https://github.com/siyuan-note/siyuan/issues/8438
This commit is contained in:
parent
7ebc8f0459
commit
e50a9b4e11
3 changed files with 13 additions and 13 deletions
|
|
@ -75,7 +75,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
|
|||
textElement.previousElementSibling.classList.remove("fn__none");
|
||||
textElement.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.classList.remove("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.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.classList.remove("fn__none");
|
||||
rightElement.lastElementChild.classList.add("fn__none");
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func openRepoSnapshotDoc(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
content, isLargeDoc, updated, err := model.OpenRepoSnapshotDoc(id)
|
||||
content, isProtyleDoc, updated, err := model.OpenRepoSnapshotDoc(id)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
@ -44,9 +44,9 @@ func openRepoSnapshotDoc(c *gin.Context) {
|
|||
}
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"content": content,
|
||||
"isLargeDoc": isLargeDoc,
|
||||
"updated": updated,
|
||||
"content": content,
|
||||
"isProtyleDoc": isProtyleDoc,
|
||||
"updated": updated,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ type TypeCount struct {
|
|||
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) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
|
|
@ -97,13 +97,13 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
|
|||
if strings.HasSuffix(file.Path, ".sy") {
|
||||
luteEngine := NewLute()
|
||||
var snapshotTree *parse.Tree
|
||||
isLargeDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
|
||||
isProtyleDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID)
|
||||
return
|
||||
}
|
||||
|
||||
if !isLargeDoc {
|
||||
if !isProtyleDoc {
|
||||
renderTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument}}
|
||||
|
||||
var unlinks []*ast.Node
|
||||
|
|
@ -133,7 +133,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isLargeDoc bool, update
|
|||
}
|
||||
|
||||
luteEngine.RenderOptions.ProtyleContenteditable = false
|
||||
if isLargeDoc {
|
||||
if isProtyleDoc {
|
||||
util.PushMsg(Conf.Language(36), 5000)
|
||||
formatRenderer := render.NewFormatRenderer(snapshotTree, luteEngine.RenderOptions)
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
isLargeDoc = true
|
||||
isProtyleDoc = true
|
||||
if strings.HasSuffix(file.Path, ".json") {
|
||||
content = gulu.Str.FromBytes(data)
|
||||
} else {
|
||||
|
|
@ -306,8 +306,8 @@ func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lut
|
|||
return
|
||||
}
|
||||
|
||||
func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isLargeDoc bool, tree *parse.Tree, err error) {
|
||||
isLargeDoc = 1024*1024*1 <= len(data)
|
||||
func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isProtyleDoc bool, tree *parse.Tree, err error) {
|
||||
isProtyleDoc = 1024*1024*1 <= len(data)
|
||||
tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
|
||||
if nil != err {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue