🎨 The embed block of a heading supports hiding the heading itself

This commit is contained in:
Achuan-2 2025-09-25 16:54:01 +08:00 committed by GitHub
parent a6e4baee99
commit ee5eb01c52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 208 additions and 45 deletions

View file

@ -251,7 +251,7 @@ func getEmbedBlock(c *gin.Context) {
for _, includeID := range includeIDsArg {
includeIDs = append(includeIDs, includeID.(string))
}
headingMode := 0 // 0带标题下方块
headingMode := 0 // 0显示标题与下方的块1仅显示标题2仅显示标题下方的块默认
headingModeArg := arg["headingMode"]
if nil != headingModeArg {
headingMode = int(headingModeArg.(float64))
@ -304,7 +304,7 @@ func searchEmbedBlock(c *gin.Context) {
for _, excludeID := range excludeIDsArg {
excludeIDs = append(excludeIDs, excludeID.(string))
}
headingMode := 0 // 0带标题下方块
headingMode := 0 // 0显示标题与下方的块1仅显示标题2仅显示标题下方的块默认
headingModeArg := arg["headingMode"]
if nil != headingModeArg {
headingMode = int(headingModeArg.(float64))

View file

@ -52,6 +52,7 @@ type Editor struct {
BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量
BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量
BacklinkContainChildren bool `json:"backlinkContainChildren"` // 反向链接是否包含子块进行计算
HeadingEmbedMode int `json:"headingEmbedMode"` // 标题嵌入块模式0显示标题与下方的块1仅显示标题2仅显示标题下方的块
Markdown *util.Markdown `json:"markdown"` // Markdown 配置
}
@ -88,6 +89,7 @@ func NewEditor() *Editor {
BacklinkExpandCount: 8,
BackmentionExpandCount: -1,
BacklinkContainChildren: true,
HeadingEmbedMode: 0,
Markdown: util.MarkdownSettings,
}
}

View file

@ -1058,16 +1058,40 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading
for _, n := range unlinks {
n.Unlink()
}
nodes = append(nodes, def)
if 0 == headingMode && ast.NodeHeading == def.Type && "1" != def.IALAttr("fold") {
children := treenode.HeadingChildren(def)
for _, c := range children {
if "1" == c.IALAttr("heading-fold") {
// 嵌入块包含折叠标题时不应该显示其下方块 https://github.com/siyuan-note/siyuan/issues/4765
continue
// headingMode: 0=显示标题与下方的块1=仅显示标题2=仅显示标题下方的块(默认)
if ast.NodeHeading == def.Type {
if 1 == headingMode {
// 仅显示标题
nodes = append(nodes, def)
} else if 2 == headingMode {
// 仅显示标题下方的块(去除标题)
if "1" != def.IALAttr("fold") {
children := treenode.HeadingChildren(def)
for _, c := range children {
if "1" == c.IALAttr("heading-fold") {
// 嵌入块包含折叠标题时不应该显示其下方块 https://github.com/siyuan-note/siyuan/issues/4765
continue
}
nodes = append(nodes, c)
}
}
} else {
// 0: 显示标题与下方的块
nodes = append(nodes, def)
if "1" != def.IALAttr("fold") {
children := treenode.HeadingChildren(def)
for _, c := range children {
if "1" == c.IALAttr("heading-fold") {
// 嵌入块包含折叠标题时不应该显示其下方块 https://github.com/siyuan-note/siyuan/issues/4765
continue
}
nodes = append(nodes, c)
}
}
nodes = append(nodes, c)
}
} else {
// 非标题块,直接添加
nodes = append(nodes, def)
}
b := treenode.GetBlockTree(def.ID)
@ -1095,7 +1119,7 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading
}
if breadcrumb {
blockPaths = buildBlockBreadcrumb(def, nil, true)
blockPaths = buildBlockBreadcrumb(def, nil, true, headingMode)
}
if 1 > len(blockPaths) {
blockPaths = []*BlockPath{}

View file

@ -495,7 +495,7 @@ func BuildBlockBreadcrumb(id string, excludeTypes []string) (ret []*BlockPath, e
return
}
func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bool) (ret []*BlockPath) {
func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bool, headingMode ...int) (ret []*BlockPath) {
ret = []*BlockPath{}
if nil == node {
return
@ -505,6 +505,12 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bo
return
}
// 默认 headingMode 为 0
mode := 0
if len(headingMode) > 0 {
mode = headingMode[0]
}
headingLevel := 16
maxNameLen := 1024
var hPath string
@ -564,8 +570,13 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bo
}
} else {
if ast.NodeDocument != parent.Type {
// 在嵌入块中隐藏最后一个非文档路径的面包屑中的文本 Hide text in breadcrumb of last non-document path in embed block https://github.com/siyuan-note/siyuan/issues/13866
name = ""
// 当headingMode=2仅显示标题下方的块且当前节点是标题时保留标题名称
if 2 == mode && ast.NodeHeading == parent.Type && parent == node {
// 保留标题名称,不清空
} else {
// 在嵌入块中隐藏最后一个非文档路径的面包屑中的文本 Hide text in breadcrumb of last non-document path in embed block https://github.com/siyuan-note/siyuan/issues/13866
name = ""
}
}
}

View file

@ -302,9 +302,37 @@ func resolveEmbedR(n *ast.Node, blockEmbedMode int, luteEngine *lute.Lute, resol
} else if "h" == sqlBlock.Type {
h := treenode.GetNodeInTree(subTree, sqlBlock.ID)
var hChildren []*ast.Node
hChildren = append(hChildren, h)
hChildren = append(hChildren, treenode.HeadingChildren(h)...)
// 从嵌入块的 IAL 属性中解析 custom-heading-mode默认值为 0
blockHeadingMode := 0 // 默认值
if customHeadingMode := n.IALAttr("custom-heading-mode"); "" != customHeadingMode {
if mode, err := strconv.Atoi(customHeadingMode); nil == err && (mode == 0 || mode == 1 || mode == 2) {
blockHeadingMode = mode
}
}
// 根据 blockHeadingMode 处理标题块的显示
// blockHeadingMode: 0=显示标题与下方的块1=仅显示标题2=仅显示标题下方的块(默认)
if 1 == blockHeadingMode {
// 仅显示标题
hChildren = append(hChildren, h)
} else if 2 == blockHeadingMode {
// 仅显示标题下方的块(默认行为)
if "1" != h.IALAttr("fold") {
children := treenode.HeadingChildren(h)
for _, c := range children {
if "1" == c.IALAttr("heading-fold") {
// 嵌入块包含折叠标题时不应该显示其下方块 https://github.com/siyuan-note/siyuan/issues/4765
continue
}
hChildren = append(hChildren, c)
}
}
} else {
// 0: 显示标题与下方的块
hChildren = append(hChildren, h)
hChildren = append(hChildren, treenode.HeadingChildren(h)...)
}
if 0 == blockEmbedMode {
embedTopLevel := 0
for _, hChild := range hChildren {