🎨 嵌入块纳入引用计数和反链 https://github.com/siyuan-note/siyuan/issues/7096

This commit is contained in:
Liang Ding 2023-01-17 22:16:14 +08:00
parent 6afa767f01
commit 492aabcf22
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 117 additions and 50 deletions

View file

@ -18,7 +18,6 @@ package treenode
import (
"bytes"
util2 "github.com/siyuan-note/siyuan/kernel/util"
"strings"
"sync"
@ -30,10 +29,62 @@ import (
"github.com/88250/lute/lex"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/88250/lute/util"
"github.com/88250/vitess-sqlparser/sqlparser"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
func GetEmbedBlockRef(embedNode *ast.Node) (blockRefID string) {
if nil == embedNode || ast.NodeBlockQueryEmbed != embedNode.Type {
return
}
scriptNode := embedNode.ChildByType(ast.NodeBlockQueryEmbedScript)
if nil == scriptNode {
return
}
stmt := scriptNode.TokensStr()
parsedStmt, err := sqlparser.Parse(stmt)
if nil != err {
return
}
switch parsedStmt.(type) {
case *sqlparser.Select:
slct := parsedStmt.(*sqlparser.Select)
if nil == slct.Where || nil == slct.Where.Expr {
return
}
switch slct.Where.Expr.(type) {
case *sqlparser.ComparisonExpr: // WHERE id = '20060102150405-1a2b3c4'
comp := slct.Where.Expr.(*sqlparser.ComparisonExpr)
switch comp.Left.(type) {
case *sqlparser.ColName:
col := comp.Left.(*sqlparser.ColName)
if nil == col || "id" != col.Name.Lowered() {
return
}
}
switch comp.Right.(type) {
case *sqlparser.SQLVal:
val := comp.Right.(*sqlparser.SQLVal)
if nil == val || sqlparser.StrVal != val.Type {
return
}
idVal := string(val.Val)
if !ast.IsNodeIDPattern(idVal) {
return
}
blockRefID = idVal
}
}
}
return
}
func GetBlockRef(n *ast.Node) (blockRefID, blockRefText, blockRefSubtype string) {
if !IsBlockRef(n) {
return
@ -52,6 +103,17 @@ func IsBlockRef(n *ast.Node) bool {
return ast.NodeTextMark == n.Type && n.IsTextMarkType("block-ref")
}
func IsFileAnnotationRef(n *ast.Node) bool {
if nil == n {
return false
}
return ast.NodeTextMark == n.Type && n.IsTextMarkType("file-annotation-ref")
}
func IsEmbedBlockRef(n *ast.Node) bool {
return "" != GetEmbedBlockRef(n)
}
func NodeStaticMdContent(node *ast.Node, luteEngine *lute.Lute) (md, content string) {
md = ExportNodeStdMd(node, luteEngine)
content = NodeStaticContent(node, nil)
@ -111,7 +173,7 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string) string {
var linkDestStr, ocrText string
if nil != linkDest {
linkDestStr = linkDest.TokensStr()
ocrText = util2.GetAssetText(linkDestStr)
ocrText = util.GetAssetText(linkDestStr)
}
linkText := n.ChildByType(ast.NodeLinkText)
@ -370,7 +432,7 @@ func IsChartCodeBlockCode(code *ast.Node) bool {
return false
}
language := util.BytesToStr(code.Previous.CodeBlockInfo)
language := gulu.Str.FromBytes(code.Previous.CodeBlockInfo)
language = strings.ReplaceAll(language, editor.Caret, "")
return render.NoHighlight(language)
}