♻️ 将解析渲染器 Protyle 项目合并到 Lute 项目中 https://github.com/siyuan-note/siyuan/issues/5602

This commit is contained in:
Liang Ding 2022-08-08 12:48:14 +08:00
parent 929b27b7f6
commit dc193ce904
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
13 changed files with 55 additions and 46 deletions

View file

@ -36,7 +36,6 @@ import (
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
util2 "github.com/88250/lute/util"
"github.com/88250/protyle"
"github.com/dustin/go-humanize"
"github.com/facette/natsort"
"github.com/gin-gonic/gin"
@ -1426,7 +1425,7 @@ func createDoc(boxID, p, title, dom string) (err error) {
updated := util.TimeFromID(id)
tree.Root.KramdownIAL = [][]string{{"id", id}, {"title", html.EscapeAttrVal(title)}, {"updated", updated}}
if nil == tree.Root.FirstChild {
tree.Root.AppendChild(protyle.NewParagraph())
tree.Root.AppendChild(parse.NewParagraph())
}
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}

View file

@ -26,7 +26,6 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -299,7 +298,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
headingNode.Unlink()
srcTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
if nil == srcTree.Root.FirstChild {
srcTree.Root.AppendChild(protyle.NewParagraph())
srcTree.Root.AppendChild(parse.NewParagraph())
}
if err = indexWriteJSONQueue(srcTree); nil != err {
return "", "", err

View file

@ -27,7 +27,7 @@ import (
"time"
"github.com/88250/gulu"
"github.com/88250/protyle"
"github.com/88250/lute/parse"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf"
@ -140,7 +140,7 @@ func GetDocHistoryContent(historyPath string) (content string, err error) {
return
}
luteEngine := NewLute()
historyTree, err := protyle.ParseJSONWithoutFix(luteEngine, data)
historyTree, err := parse.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
if nil != err {
logging.LogErrorf("parse tree from file [%s] failed, remove it", historyPath)
os.RemoveAll(historyPath)
@ -291,7 +291,7 @@ func GetDocHistory(boxID string) (ret []*History, err error) {
logging.LogErrorf("read file [%s] failed: %s", path, err)
return nil
}
historyTree, err := protyle.ParseJSONWithoutFix(luteEngine, data)
historyTree, err := parse.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
if nil != err {
logging.LogErrorf("parse tree from file [%s] failed, remove it", path)
os.RemoveAll(path)

View file

@ -38,7 +38,7 @@ import (
"github.com/88250/lute/html"
"github.com/88250/lute/html/atom"
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/88250/lute/render"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
@ -94,7 +94,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
err = readErr
return
}
tree, _, parseErr := protyle.ParseJSON(luteEngine, data)
tree, _, parseErr := parse.ParseJSON(data, luteEngine.ParseOptions)
if nil != parseErr {
logging.LogErrorf("parse .sy [%s] failed: %s", syPath, parseErr)
err = parseErr
@ -144,7 +144,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
// 写回 .sy
for _, tree := range trees {
syPath := filepath.Join(unzipRootPath, tree.Path)
renderer := protyle.NewJSONRenderer(tree, luteEngine.RenderOptions)
renderer := render.NewJSONRenderer(tree, luteEngine.RenderOptions)
data := renderer.Render()
buf := bytes.Buffer{}

View file

@ -21,7 +21,6 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -73,7 +72,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
children = append(children, c)
}
if 1 > len(children) {
newNode := protyle.NewParagraph()
newNode := parse.NewParagraph()
children = append(children, newNode)
}
@ -96,7 +95,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
}
srcTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
if nil == srcTree.Root.FirstChild {
srcTree.Root.AppendChild(protyle.NewParagraph())
srcTree.Root.AppendChild(parse.NewParagraph())
}
if err = indexWriteJSONQueue(srcTree); nil != err {
return "", "", err

View file

@ -31,7 +31,6 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/88250/protyle"
"github.com/araddon/dateparse"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -215,7 +214,7 @@ func renderTemplate(p, id string) (string, error) {
return ast.WalkContinue
})
for _, n := range nodesNeedAppendChild {
n.AppendChild(protyle.NewParagraph())
n.AppendChild(parse.NewParagraph())
}
// 折叠标题导出为模板后使用会出现内容重复 https://github.com/siyuan-note/siyuan/issues/4488

View file

@ -24,7 +24,6 @@ import (
"github.com/88250/lute"
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
@ -59,7 +58,7 @@ func loadTree(localPath string, luteEngine *lute.Lute) (ret *parse.Tree, err err
return
}
ret, err = protyle.ParseJSONWithoutFix(luteEngine, data)
ret, err = parse.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
if nil != err {
logging.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
return