How to deal with empty content

I‘m using nested block to wrap my context, but it cannot handle empty content.

#let wrapp-section(
  body, // The body content / 主体内容
  depth: 1, // The heading depth to wrap / 要包装的标题深度
  wrapper: none, // The wrapper function / 包装函数
) = {
...

  for it in body.children { // 无法处理标题下没有子元素的情况 Cannot handle cases where there are no child elements under the heading.
    let x = it.func(); // Get the function name of the element / 获取元素的函数名称
...

I don’t fully understand what you mean, but perhaps you can circumvent it by replacing body.children with body.at("children", default: ()).

1 Like

Content is not always a sequence, any element alone can also be content too for example. Maybe you could handle it using some kind of either-or (either a sequence or it’s just a single thing).

See Document all possible `content` functions · Issue #7487 · typst/typst · GitHub.

1 Like