mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40: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)
|
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 {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
|
||||||
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
dom := renderBlockDOMByNodes(renderNodes, luteEngine)
|
||||||
ret = &Backlink{
|
ret = &Backlink{
|
||||||
DOM: dom,
|
DOM: dom,
|
||||||
BlockPaths: buildBlockBreadcrumb(n),
|
BlockPaths: buildBlockBreadcrumb(n, nil),
|
||||||
Expand: expand,
|
Expand: expand,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -468,7 +468,7 @@ func getEmbeddedBlock(embedBlockID string, trees map[string]*parse.Tree, sqlBloc
|
||||||
}
|
}
|
||||||
|
|
||||||
if breadcrumb && !inSuperBlock {
|
if breadcrumb && !inSuperBlock {
|
||||||
blockPaths = buildBlockBreadcrumb(def)
|
blockPaths = buildBlockBreadcrumb(def, nil)
|
||||||
}
|
}
|
||||||
if 1 > len(blockPaths) {
|
if 1 > len(blockPaths) {
|
||||||
blockPaths = []*BlockPath{}
|
blockPaths = []*BlockPath{}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
||||||
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
||||||
node = treenode.FirstLeafBlock(node)
|
node = treenode.FirstLeafBlock(node)
|
||||||
}
|
}
|
||||||
content := treenode.NodeStaticContent(node)
|
content := treenode.NodeStaticContent(node, nil)
|
||||||
content = gulu.Str.SubStr(content, 128)
|
content = gulu.Str.SubStr(content, 128)
|
||||||
err = SetCloudBlockReminder(id, content, timedMills)
|
err = SetCloudBlockReminder(id, content, timedMills)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func getNodeRefText(node *ast.Node) string {
|
||||||
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
if ast.NodeDocument != node.Type && node.IsContainerBlock() {
|
||||||
node = treenode.FirstLeafBlock(node)
|
node = treenode.FirstLeafBlock(node)
|
||||||
}
|
}
|
||||||
ret := renderBlockText(node)
|
ret := renderBlockText(node, nil)
|
||||||
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(ret) {
|
if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(ret) {
|
||||||
ret = gulu.Str.SubStr(ret, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..."
|
ret = gulu.Str.SubStr(ret, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..."
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ type BlockPath struct {
|
||||||
Children []*BlockPath `json:"children"`
|
Children []*BlockPath `json:"children"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildBlockBreadcrumb(id string) (ret []*BlockPath, err error) {
|
func BuildBlockBreadcrumb(id string, excludeTypes []string) (ret []*BlockPath, err error) {
|
||||||
ret = []*BlockPath{}
|
ret = []*BlockPath{}
|
||||||
tree, err := loadTreeByBlockID(id)
|
tree, err := loadTreeByBlockID(id)
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
|
|
@ -205,11 +205,11 @@ func BuildBlockBreadcrumb(id string) (ret []*BlockPath, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = buildBlockBreadcrumb(node)
|
ret = buildBlockBreadcrumb(node, excludeTypes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPath) {
|
||||||
ret = []*BlockPath{}
|
ret = []*BlockPath{}
|
||||||
if nil == node {
|
if nil == node {
|
||||||
return
|
return
|
||||||
|
|
@ -243,9 +243,9 @@ func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
||||||
} else {
|
} else {
|
||||||
if "" == name {
|
if "" == name {
|
||||||
if ast.NodeListItem == parent.Type {
|
if ast.NodeListItem == parent.Type {
|
||||||
name = gulu.Str.SubStr(renderBlockText(fc), maxNameLen)
|
name = gulu.Str.SubStr(renderBlockText(fc, excludeTypes), maxNameLen)
|
||||||
} else {
|
} else {
|
||||||
name = gulu.Str.SubStr(renderBlockText(parent), maxNameLen)
|
name = gulu.Str.SubStr(renderBlockText(parent, excludeTypes), maxNameLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ast.NodeHeading == parent.Type {
|
if ast.NodeHeading == parent.Type {
|
||||||
|
|
@ -262,7 +262,7 @@ func buildBlockBreadcrumb(node *ast.Node) (ret []*BlockPath) {
|
||||||
}
|
}
|
||||||
if ast.NodeListItem == parent.Type {
|
if ast.NodeListItem == parent.Type {
|
||||||
if "" == name {
|
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 {
|
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{{
|
ret = append([]*BlockPath{{
|
||||||
ID: b.ID,
|
ID: b.ID,
|
||||||
Name: name,
|
Name: name,
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,8 @@ func renderOutline(node *ast.Node, luteEngine *lute.Lute) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderBlockText(node *ast.Node) (ret string) {
|
func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
|
||||||
ret = treenode.NodeStaticContent(node)
|
ret = treenode.NodeStaticContent(node, excludeTypes)
|
||||||
ret = strings.TrimSpace(ret)
|
ret = strings.TrimSpace(ret)
|
||||||
ret = strings.ReplaceAll(ret, "\n", "")
|
ret = strings.ReplaceAll(ret, "\n", "")
|
||||||
ret = html.EscapeString(ret)
|
ret = html.EscapeString(ret)
|
||||||
|
|
|
||||||
|
|
@ -623,7 +623,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
||||||
} else if n.IsContainerBlock() {
|
} else if n.IsContainerBlock() {
|
||||||
markdown, content = treenode.NodeStaticMdContent(n, luteEngine)
|
markdown, content = treenode.NodeStaticMdContent(n, luteEngine)
|
||||||
fc := treenode.FirstLeafBlock(n)
|
fc := treenode.FirstLeafBlock(n)
|
||||||
fcontent = treenode.NodeStaticContent(fc)
|
fcontent = treenode.NodeStaticContent(fc, nil)
|
||||||
parentID = n.Parent.ID
|
parentID = n.Parent.ID
|
||||||
// 将标题块作为父节点
|
// 将标题块作为父节点
|
||||||
if h := heading(n); nil != h {
|
if h := heading(n); nil != h {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package treenode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/88250/gulu"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -52,7 +53,7 @@ func IsBlockRef(n *ast.Node) bool {
|
||||||
|
|
||||||
func NodeStaticMdContent(node *ast.Node, luteEngine *lute.Lute) (md, content string) {
|
func NodeStaticMdContent(node *ast.Node, luteEngine *lute.Lute) (md, content string) {
|
||||||
md = ExportNodeStdMd(node, luteEngine)
|
md = ExportNodeStdMd(node, luteEngine)
|
||||||
content = NodeStaticContent(node)
|
content = NodeStaticContent(node, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +75,7 @@ func ExportNodeStdMd(node *ast.Node, luteEngine *lute.Lute) string {
|
||||||
return markdown
|
return markdown
|
||||||
}
|
}
|
||||||
|
|
||||||
func NodeStaticContent(node *ast.Node) string {
|
func NodeStaticContent(node *ast.Node, excludeTypes []string) string {
|
||||||
if nil == node {
|
if nil == node {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
@ -99,6 +100,10 @@ func NodeStaticContent(node *ast.Node) string {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gulu.Str.Contains(n.Type.String(), excludeTypes) {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
switch n.Type {
|
switch n.Type {
|
||||||
case ast.NodeLinkText:
|
case ast.NodeLinkText:
|
||||||
buf.Write(n.Tokens)
|
buf.Write(n.Tokens)
|
||||||
|
|
@ -116,6 +121,14 @@ func NodeStaticContent(node *ast.Node) string {
|
||||||
}
|
}
|
||||||
buf.Write(tokens)
|
buf.Write(tokens)
|
||||||
case ast.NodeTextMark:
|
case ast.NodeTextMark:
|
||||||
|
for _, excludeType := range excludeTypes {
|
||||||
|
if strings.HasPrefix(excludeType, "TextMark-") {
|
||||||
|
if n.IsTextMarkType(excludeType[9:]) {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if n.IsTextMarkType("tag") {
|
if n.IsTextMarkType("tag") {
|
||||||
buf.WriteByte('#')
|
buf.WriteByte('#')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue