mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
🎨 间隔复习界面面包屑不包含标记元素
This commit is contained in:
parent
855b92f4ca
commit
3db25a7259
8 changed files with 38 additions and 17 deletions
|
|
@ -325,7 +325,15 @@ func getBlockBreadcrumb(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
blockPath, err := model.BuildBlockBreadcrumb(id)
|
||||
excludeTypesArg := arg["excludeTypes"]
|
||||
var excludeTypes []string
|
||||
if nil != excludeTypesArg {
|
||||
for _, excludeType := range excludeTypesArg.([]interface{}) {
|
||||
excludeTypes = append(excludeTypes, excludeType.(string))
|
||||
}
|
||||
}
|
||||
|
||||
blockPath, err := model.BuildBlockBreadcrumb(id, excludeTypes)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
|
|||
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
||||
ret = &Backlink{
|
||||
DOM: dom,
|
||||
BlockPaths: buildBlockBreadcrumb(n),
|
||||
BlockPaths: buildBlockBreadcrumb(n, nil),
|
||||
Expand: expand,
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ func getEmbeddedBlock(embedBlockID string, trees map[string]*parse.Tree, sqlBloc
|
|||
}
|
||||
|
||||
if breadcrumb && !inSuperBlock {
|
||||
blockPaths = buildBlockBreadcrumb(def)
|
||||
blockPaths = buildBlockBreadcrumb(def, nil)
|
||||
}
|
||||
if 1 > len(blockPaths) {
|
||||
blockPaths = []*BlockPath{}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
||||
node = treenode.FirstLeafBlock(node)
|
||||
}
|
||||
content := treenode.NodeStaticContent(node)
|
||||
content := treenode.NodeStaticContent(node, nil)
|
||||
content = gulu.Str.SubStr(content, 128)
|
||||
err = SetCloudBlockReminder(id, content, timedMills)
|
||||
if nil != err {
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func getNodeRefText(node *ast.Node) string {
|
|||
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
||||
node = treenode.FirstLeafBlock(node)
|
||||
}
|
||||
ret := renderBlockText(node)
|
||||
ret := renderBlockText(node, nil)
|
||||
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(ret) {
|
||||
ret = gulu.Str.SubStr(ret, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..."
|
||||
}
|
||||
|
|
@ -193,7 +193,7 @@ type BlockPath struct {
|
|||
Children []*BlockPath `json:"children"`
|
||||
}
|
||||
|
||||
func BuildBlockBreadcrumb(id string) (ret []*BlockPath, err error) {
|
||||
func BuildBlockBreadcrumb(id string, excludeTypes []string) (ret []*BlockPath, err error) {
|
||||
ret = []*BlockPath{}
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil == tree {
|
||||
|
|
@ -205,11 +205,11 @@ func BuildBlockBreadcrumb(id string) (ret []*BlockPath, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
ret = buildBlockBreadcrumb(node)
|
||||
ret = buildBlockBreadcrumb(node, excludeTypes)
|
||||
return
|
||||
}
|
||||
|
||||
func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
||||
func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPath) {
|
||||
ret = []*BlockPath{}
|
||||
if nil == node {
|
||||
return
|
||||
|
|
@ -243,9 +243,9 @@ func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
|||
} else {
|
||||
if "" == name {
|
||||
if ast.NodeListItem == parent.Type {
|
||||
name = gulu.Str.SubStr(renderBlockText(fc), maxNameLen)
|
||||
name = gulu.Str.SubStr(renderBlockText(fc, excludeTypes), maxNameLen)
|
||||
} else {
|
||||
name = gulu.Str.SubStr(renderBlockText(parent), maxNameLen)
|
||||
name = gulu.Str.SubStr(renderBlockText(parent, excludeTypes), maxNameLen)
|
||||
}
|
||||
}
|
||||
if ast.NodeHeading == parent.Type {
|
||||
|
|
@ -262,7 +262,7 @@ func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
|||
}
|
||||
if ast.NodeListItem == parent.Type {
|
||||
if "" == name {
|
||||
name = gulu.Str.SubStr(renderBlockText(fc), maxNameLen)
|
||||
name = gulu.Str.SubStr(renderBlockText(fc, excludeTypes), maxNameLen)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
|||
}
|
||||
|
||||
if ast.NodeHeading == b.Type && headingLevel > b.HeadingLevel {
|
||||
name = gulu.Str.SubStr(renderBlockText(b), maxNameLen)
|
||||
name = gulu.Str.SubStr(renderBlockText(b, excludeTypes), maxNameLen)
|
||||
ret = append([]*BlockPath{{
|
||||
ID: b.ID,
|
||||
Name: name,
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ func renderOutline(node *ast.Node, luteEngine *lute.Lute) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func renderBlockText(node *ast.Node) (ret string) {
|
||||
ret = treenode.NodeStaticContent(node)
|
||||
func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
|
||||
ret = treenode.NodeStaticContent(node, excludeTypes)
|
||||
ret = strings.TrimSpace(ret)
|
||||
ret = strings.ReplaceAll(ret, "\n", "")
|
||||
ret = html.EscapeString(ret)
|
||||
|
|
|
|||
|
|
@ -623,7 +623,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
|||
} else if n.IsContainerBlock() {
|
||||
markdown, content = treenode.NodeStaticMdContent(n, luteEngine)
|
||||
fc := treenode.FirstLeafBlock(n)
|
||||
fcontent = treenode.NodeStaticContent(fc)
|
||||
fcontent = treenode.NodeStaticContent(fc, nil)
|
||||
parentID = n.Parent.ID
|
||||
// 将标题块作为父节点
|
||||
if h := heading(n); nil != h {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package treenode
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/88250/gulu"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ func IsBlockRef(n *ast.Node) bool {
|
|||
|
||||
func NodeStaticMdContent(node *ast.Node, luteEngine *lute.Lute) (md, content string) {
|
||||
md = ExportNodeStdMd(node, luteEngine)
|
||||
content = NodeStaticContent(node)
|
||||
content = NodeStaticContent(node, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ func ExportNodeStdMd(node *ast.Node, luteEngine *lute.Lute) string {
|
|||
return markdown
|
||||
}
|
||||
|
||||
func NodeStaticContent(node *ast.Node) string {
|
||||
func NodeStaticContent(node *ast.Node, excludeTypes []string) string {
|
||||
if nil == node {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -99,6 +100,10 @@ func NodeStaticContent(node *ast.Node) string {
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
if gulu.Str.Contains(n.Type.String(), excludeTypes) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
switch n.Type {
|
||||
case ast.NodeLinkText:
|
||||
buf.Write(n.Tokens)
|
||||
|
|
@ -116,6 +121,14 @@ func NodeStaticContent(node *ast.Node) string {
|
|||
}
|
||||
buf.Write(tokens)
|
||||
case ast.NodeTextMark:
|
||||
for _, excludeType := range excludeTypes {
|
||||
if strings.HasPrefix(excludeType, "TextMark-") {
|
||||
if n.IsTextMarkType(excludeType[9:]) {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if n.IsTextMarkType("tag") {
|
||||
buf.WriteByte('#')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue