mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-25 01:36:09 +01:00
🎨 标题块支持复制下方块 https://github.com/siyuan-note/siyuan/issues/5450
This commit is contained in:
parent
06b88df2dd
commit
daa29df6fc
4 changed files with 92 additions and 57 deletions
|
|
@ -17,6 +17,9 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -85,6 +88,80 @@ func RecentUpdatedBlocks() (ret []*Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetHeadingChildrenDOM(id string) (ret string) {
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
heading := treenode.GetNodeInTree(tree, id)
|
||||
if nil == heading || ast.NodeHeading != heading.Type {
|
||||
return
|
||||
}
|
||||
|
||||
nodes := append([]*ast.Node{}, heading)
|
||||
children := treenode.HeadingChildren(heading)
|
||||
nodes = append(nodes, children...)
|
||||
luteEngine := NewLute()
|
||||
ret = renderBlockDOMByNodes(nodes, luteEngine)
|
||||
return
|
||||
}
|
||||
|
||||
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 GetBlockDOM(id string) (ret string) {
|
||||
if "" == id {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue