🎨 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

@ -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 {