Skip to content

Commit

Permalink
🎨 Improve export of heading levels in embedded blocks #12233
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 12, 2024
1 parent 5347121 commit 1ae194c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions kernel/model/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ func resolveEmbedR(n *ast.Node, blockEmbedMode int, luteEngine *lute.Lute, resol

for _, child := range children {
var unlinks []*ast.Node

parentHeadingLevel := 0
for prev := child; nil != prev; prev = prev.Previous {
if ast.NodeHeading == prev.Type {
parentHeadingLevel = prev.HeadingLevel
break
}
}

ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
Expand Down Expand Up @@ -214,6 +223,29 @@ func resolveEmbedR(n *ast.Node, blockEmbedMode int, luteEngine *lute.Lute, resol
var hChildren []*ast.Node
hChildren = append(hChildren, h)
hChildren = append(hChildren, treenode.HeadingChildren(h)...)

if 0 == blockEmbedMode {
// 嵌入块中出现了大于等于上方非嵌入块的标题时需要降低嵌入块中的标题级别
// Improve export of heading levels in embedded blocks https://github.com/siyuan-note/siyuan/issues/12233
embedTopLevel := 0
for _, hChild := range hChildren {
if ast.NodeHeading == hChild.Type {
embedTopLevel = hChild.HeadingLevel
break
}
}
if parentHeadingLevel >= embedTopLevel {
for _, hChild := range hChildren {
if ast.NodeHeading == hChild.Type {
hChild.HeadingLevel += parentHeadingLevel - embedTopLevel + 1
if 6 < hChild.HeadingLevel {
hChild.HeadingLevel = 6
}
}
}
}
}

mdBuf := &bytes.Buffer{}
for _, hChild := range hChildren {
md, _ = lute.FormatNodeSync(hChild, luteEngine.ParseOptions, luteEngine.RenderOptions)
Expand Down

0 comments on commit 1ae194c

Please sign in to comment.