This commit is contained in:
Liang Ding 2022-09-27 21:52:30 +08:00
parent 06b88df2dd
commit daa29df6fc
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 92 additions and 57 deletions

View file

@ -22,7 +22,6 @@ import (
"time"
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
"github.com/88250/lute/lex"
@ -33,62 +32,6 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func GetHeadingLevelTransaction(id string, level int) (transaction *Transaction, err error) {
tree, err := loadTreeByBlockID(id)
if nil != err {
return
}
node := treenode.GetNodeInTree(tree, id)
if nil == node {
err = errors.New(fmt.Sprintf(Conf.Language(15), id))
return
}
if ast.NodeHeading != node.Type {
return
}
hLevel := node.HeadingLevel
if hLevel == level {
return
}
diff := level - hLevel
var children, childrenHeadings []*ast.Node
children = append(children, node)
children = append(children, treenode.HeadingChildren(node)...)
for _, c := range children {
if ast.NodeHeading == c.Type {
childrenHeadings = append(childrenHeadings, c)
}
}
transaction = &Transaction{}
luteEngine := NewLute()
for _, c := range childrenHeadings {
op := &Operation{}
op.ID = c.ID
op.Action = "update"
op.Data = lute.RenderNodeBlockDOM(c, luteEngine.ParseOptions, luteEngine.RenderOptions)
transaction.UndoOperations = append(transaction.UndoOperations, op)
c.HeadingLevel += diff
if 6 < c.HeadingLevel {
c.HeadingLevel = 6
} else if 1 > c.HeadingLevel {
c.HeadingLevel = 1
}
op = &Operation{}
op.ID = c.ID
op.Action = "update"
op.Data = lute.RenderNodeBlockDOM(c, luteEngine.ParseOptions, luteEngine.RenderOptions)
transaction.DoOperations = append(transaction.DoOperations, op)
}
return
}
func SetBlockReminder(id string, timed string) (err error) {
if !IsSubscriber() {
if "ios" == util.Container {