♻️ 移除旧版中的行级元素实现代码 https://github.com/siyuan-note/siyuan/issues/6819

This commit is contained in:
Liang Ding 2022-12-08 20:32:42 +08:00
parent c69983c56c
commit 637f1427e4
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
11 changed files with 24 additions and 322 deletions

View file

@ -1100,15 +1100,6 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool) (re
return ast.WalkContinue
}
}
case ast.NodeFileAnnotationRef:
refIDNode := n.ChildByType(ast.NodeFileAnnotationRefID)
if nil == refIDNode {
return ast.WalkSkipChildren
}
refID := refIDNode.TokensStr()
status := processFileAnnotationRef(refID, n)
unlinks = append(unlinks, n)
return status
}
if !treenode.IsBlockRef(n) {
@ -1534,16 +1525,7 @@ func processFileAnnotationRef(refID string, n *ast.Node) ast.WalkStatus {
page := int(pages[0].(map[string]interface{})["index"].(float64)) + 1
pageStr := strconv.Itoa(page)
var refText string
if ast.NodeTextMark == n.Type {
refText = n.TextMarkTextContent
} else {
refTextNode := n.ChildByType(ast.NodeFileAnnotationRefText)
if nil == refTextNode {
return ast.WalkSkipChildren
}
refText = refTextNode.TokensStr()
}
refText := n.TextMarkTextContent
ext := filepath.Ext(p)
file := p[7:len(p)-23-len(ext)] + ext
fileAnnotationRefLink := &ast.Node{Type: ast.NodeLink}

View file

@ -128,17 +128,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
if !entering {
return ast.WalkContinue
}
if treenode.IsBlockRef(n) {
defID, _, _ := treenode.GetBlockRef(n)
newDefID := blockIDs[defID]
if "" != newDefID {
if ast.NodeBlockRef == n.Type {
if id := n.ChildByType(ast.NodeBlockRefID); nil != id {
id.Tokens = []byte(newDefID)
}
} else {
n.TextMarkBlockRefID = newDefID
}
n.TextMarkBlockRefID = newDefID
}
} else if ast.NodeBlockQueryEmbedScript == n.Type {
for oldID, newID := range blockIDs {

View file

@ -25,7 +25,6 @@ import (
"strings"
"time"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/dustin/go-humanize"
"github.com/emirpasic/gods/sets/hashset"
@ -251,10 +250,6 @@ func IndexRefs() {
logging.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds())
}
func isLegacyDynamicBlockRef(blockRef *ast.Node) bool {
return nil == blockRef.ChildByType(ast.NodeBlockRefText) && nil == blockRef.ChildByType(ast.NodeBlockRefDynamicText)
}
func init() {
eventbus.Subscribe(eventbus.EvtSQLInsertBlocks, func(context map[string]interface{}, blockCount int, hash string) {
if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container {

View file

@ -46,10 +46,7 @@ func renderOutline(node *ast.Node, luteEngine *lute.Lute) (ret string) {
return ast.WalkContinue
}
switch n.Type {
case ast.NodeBlockRef:
buf.WriteString(html.EscapeString(treenode.GetDynamicBlockRefText(n)))
return ast.WalkSkipChildren
case ast.NodeText, ast.NodeLinkText, ast.NodeFileAnnotationRefText, ast.NodeFootnotesRef, ast.NodeCodeBlockCode, ast.NodeMathBlockContent:
case ast.NodeText, ast.NodeLinkText, ast.NodeFootnotesRef, ast.NodeCodeBlockCode, ast.NodeMathBlockContent:
tokens := html.EscapeHTML(n.Tokens)
tokens = bytes.ReplaceAll(tokens, []byte(" "), []byte(" ")) // 大纲面板条目中无法显示多个空格 https://github.com/siyuan-note/siyuan/issues/4370
buf.Write(tokens)

View file

@ -20,15 +20,6 @@ import (
"bytes"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
"time"
"unicode/utf8"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
@ -36,6 +27,13 @@ import (
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
"time"
"github.com/88250/gulu"
sprig "github.com/Masterminds/sprig/v3"
@ -224,15 +222,6 @@ func renderTemplate(p, id string) (string, error) {
unlinks = append(unlinks, n)
}
}
} else if ast.NodeBlockRef == n.Type {
if idNode := n.ChildByType(ast.NodeBlockRefID); nil != idNode {
refText := sql.GetRefText(idNode.TokensStr())
if "" != refText {
treenode.SetDynamicBlockRefText(n, refText)
} else {
unlinks = append(unlinks, n)
}
}
}
return ast.WalkContinue
})
@ -260,25 +249,6 @@ func renderTemplate(p, id string) (string, error) {
return dom, nil
}
func appendRefTextRenderResultForBlockRef(blockRef *ast.Node) {
if !treenode.IsBlockRef(blockRef) {
return
}
refID, text, _ := treenode.GetBlockRef(blockRef)
if "" != text {
return
}
// 动态解析渲染 ((id)) 的锚文本
// 现行版本已经不存在该语法情况,这里保留是为了迁移历史数据
text = sql.GetRefText(refID)
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(text) {
text = gulu.Str.SubStr(text, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..."
}
blockRef.AppendChild(&ast.Node{Type: ast.NodeBlockRefDynamicText, Tokens: gulu.Str.ToBytes(text)})
}
func addBlockIALNodes(tree *parse.Tree, removeUpdated bool) {
var blocks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {

View file

@ -909,8 +909,6 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
}
}
}
} else if ast.NodeBlockRef == n.Type {
sql.CacheRef(subTree, n)
}
return ast.WalkContinue
})

View file

@ -91,9 +91,7 @@ func resetTree(tree *parse.Tree, titleSuffix string) {
return ast.WalkContinue
}
if "1" != refIDs[defID] {
if ast.NodeBlockRefID == n.Type {
n.Tokens = []byte(refIDs[defID])
} else if ast.NodeTextMark == n.Type {
if ast.NodeTextMark == n.Type {
n.TextMarkBlockRefID = refIDs[defID]
}
}