Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-09-30 22:44:51 +08:00
commit ae8ce006ba
3 changed files with 7 additions and 38 deletions

View File

@ -91,7 +91,10 @@ func GetBlockRefText(id string) string {
if nil == node { if nil == node {
return ErrBlockNotFound.Error() return ErrBlockNotFound.Error()
} }
return getNodeRefText(node)
}
func getNodeRefText(node *ast.Node) string {
if name := node.IALAttr("name"); "" != name { if name := node.IALAttr("name"); "" != name {
return name return name
} }

View File

@ -24,9 +24,7 @@ import (
"sort" "sort"
"strings" "strings"
"time" "time"
"unicode/utf8"
"github.com/88250/gulu"
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
"github.com/88250/lute/parse" "github.com/88250/lute/parse"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
@ -251,7 +249,7 @@ func IndexRefs() {
logging.LogErrorf("tree [%s] dynamic ref text to static failed: %s", dynamicRefTreeID, err) logging.LogErrorf("tree [%s] dynamic ref text to static failed: %s", dynamicRefTreeID, err)
continue continue
} }
legacyDynamicRefTreeToStatic(tree)
if err := filesys.WriteTree(tree); nil == err { if err := filesys.WriteTree(tree); nil == err {
//logging.LogInfof("persisted tree [%s] dynamic ref text", tree.Box+tree.Path) //logging.LogInfof("persisted tree [%s] dynamic ref text", tree.Box+tree.Path)
} }
@ -319,35 +317,6 @@ func IndexRefs() {
logging.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds()) logging.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds())
} }
func legacyDynamicRefTreeToStatic(tree *parse.Tree) {
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeBlockRef != n.Type {
return ast.WalkContinue
}
if isLegacyDynamicBlockRef(n) {
idNode := n.ChildByType(ast.NodeBlockRefID)
defID := idNode.TokensStr()
def := sql.GetBlock(defID)
var text string
if nil == def {
if "zh_CN" == Conf.Lang {
text = "解析引用锚文本失败,请尝试更新该引用指向的定义块后再重新打开该文档"
} else {
text = "Failed to parse the ref anchor text, please try to update the def block pointed to by the ref and then reopen this document"
}
} else {
text = sql.GetRefText(defID)
}
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(text) {
text = gulu.Str.SubStr(text, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..."
}
treenode.SetDynamicBlockRefText(n, text)
return ast.WalkSkipChildren
}
return ast.WalkContinue
})
}
func isLegacyDynamicBlockRef(blockRef *ast.Node) bool { func isLegacyDynamicBlockRef(blockRef *ast.Node) bool {
return nil == blockRef.ChildByType(ast.NodeBlockRefText) && nil == blockRef.ChildByType(ast.NodeBlockRefDynamicText) return nil == blockRef.ChildByType(ast.NodeBlockRefText) && nil == blockRef.ChildByType(ast.NodeBlockRefDynamicText)
} }

View File

@ -24,7 +24,6 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"unicode/utf8"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
@ -1131,11 +1130,9 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha
if ast.NodeDocument != defNode.Type && defNode.IsContainerBlock() { if ast.NodeDocument != defNode.Type && defNode.IsContainerBlock() {
defNode = treenode.FirstLeafBlock(defNode) defNode = treenode.FirstLeafBlock(defNode)
} }
defContent := renderBlockText(defNode)
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(defContent) { refText := getNodeRefText(defNode)
defContent = gulu.Str.SubStr(defContent, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..." treenode.SetDynamicBlockRefText(n, refText)
}
treenode.SetDynamicBlockRefText(n, defContent)
changed = true changed = true
return ast.WalkContinue return ast.WalkContinue
}) })