♻️ 将解析渲染器 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

File diff suppressed because one or more lines are too long

View file

@ -22,7 +22,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
"github.com/88250/protyle"
"github.com/88250/lute/parse"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@ -294,7 +294,7 @@ func dataBlockDOM(data string, luteEngine *lute.Lute) (ret string) {
ret = luteEngine.Md2BlockDOM(data)
if "" == ret {
// 使用 API 插入空字符串出现错误 https://github.com/siyuan-note/siyuan/issues/3931
blankParagraph := protyle.NewParagraph()
blankParagraph := parse.NewParagraph()
ret = lute.RenderNodeBlockDOM(blankParagraph, luteEngine.ParseOptions, luteEngine.RenderOptions)
}
return

View file

@ -25,7 +25,6 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/88250/protyle"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model"
@ -70,7 +69,7 @@ func html2BlockDOM(c *gin.Context) {
}
if ast.NodeListItem == n.Type && nil == n.FirstChild {
newNode := protyle.NewParagraph()
newNode := parse.NewParagraph()
n.AppendChild(newNode)
n.SetIALAttr("updated", util.TimeFromID(newNode.ID))
return ast.WalkSkipChildren

View file

@ -28,7 +28,7 @@ import (
"github.com/88250/lute"
"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/cache"
@ -78,7 +78,7 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
hPathBuilder.WriteString("Untitled/")
continue
}
parentTree, parseErr := protyle.ParseJSONWithoutFix(luteEngine, parentData)
parentTree, parseErr := parse.ParseJSONWithoutFix(parentData, luteEngine.ParseOptions)
if nil != parseErr {
logging.LogWarnf("parse parent tree [%s] failed: %s", parentPath, parseErr)
hPathBuilder.WriteString("Untitled/")
@ -97,12 +97,12 @@ func WriteTree(tree *parse.Tree) (err error) {
luteEngine := util.NewLute() // 不关注用户的自定义解析渲染选项
if nil == tree.Root.FirstChild {
newP := protyle.NewParagraph()
newP := parse.NewParagraph()
tree.Root.AppendChild(newP)
tree.Root.SetIALAttr("updated", util.TimeFromID(newP.ID))
}
renderer := protyle.NewJSONRenderer(tree, luteEngine.RenderOptions)
renderer := render.NewJSONRenderer(tree, luteEngine.RenderOptions)
output := renderer.Render()
// .sy 文档数据使用格式化好的 JSON 而非单行 JSON
@ -172,7 +172,7 @@ func recoverParseJSON2Tree(boxID, p, filePath string, luteEngine *lute.Lute) (re
func parseJSON2Tree(boxID, p string, jsonData []byte, luteEngine *lute.Lute) (ret *parse.Tree) {
var err error
var needFix bool
ret, needFix, err = protyle.ParseJSON(luteEngine, jsonData)
ret, needFix, err = parse.ParseJSON(jsonData, luteEngine.ParseOptions)
if nil != err {
logging.LogErrorf("parse json [%s] to tree failed: %s", boxID+p, err)
return
@ -181,7 +181,7 @@ func parseJSON2Tree(boxID, p string, jsonData []byte, luteEngine *lute.Lute) (re
ret.Box = boxID
ret.Path = p
if needFix {
renderer := protyle.NewJSONRenderer(ret, luteEngine.RenderOptions)
renderer := render.NewJSONRenderer(ret, luteEngine.RenderOptions)
output := renderer.Render()
buf := bytes.Buffer{}

View file

@ -7,10 +7,9 @@ require (
github.com/88250/css v0.1.2
github.com/88250/flock v0.8.2
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583
github.com/88250/lute v1.7.5-0.20220805051605-c55f139858b7
github.com/88250/lute v1.7.5-0.20220808043452-0771b1423c31
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1
github.com/88250/pdfcpu v0.3.13
github.com/88250/protyle v0.0.0-20220808015153-2743f8d8dd1b
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732
github.com/Masterminds/sprig/v3 v3.2.2
@ -131,7 +130,6 @@ replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20
//replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
//replace github.com/88250/enumfonts => D:\88250\enumfonts
//replace github.com/88250/pdfcpu => D:\88250\pdfcpu
//replace github.com/88250/protyle => D:\88250\protyle
//replace github.com/88250/gulu => D:\88250\gulu
//replace github.com/88250/melody => D:\88250\melody
//replace github.com/mattn/go-sqlite3 => D:\88250\go-sqlite3

View file

@ -56,8 +56,9 @@ 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.20220720144315-065ef35ec583 h1:FhA/zJemLrbOYJpdMIMBezO5rGigQSdPR1kv+aztHfA=
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
github.com/88250/lute v1.7.5-0.20220805051605-c55f139858b7 h1:O0B/mdbIE3tSjblhhpNd0PTavx9WxXql+qmLrlyBBls=
github.com/88250/lute v1.7.5-0.20220805051605-c55f139858b7/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
github.com/88250/lute v1.7.5-0.20220808043452-0771b1423c31 h1:uHqRSyyRp8koO/XakoCoswLwu/cp25VnXZFt8WvcSb8=
github.com/88250/lute v1.7.5-0.20220808043452-0771b1423c31/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s=
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI=
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=

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