How to add a `lorem(50)` after every heading?

How can I add a lorem(50) after every heading ?

I tried

show heading: it => {
  it
  lorem(50)
}

But this prints the lorem in heading style.

I also tried something like

let add-lorem(elem) = {
  if type(elem) == heading {
    elem + lorem(50)
  } else {
    elem
  }
}

show: add-lorem

= Intro

== ...
===....

but also didn’t work.

Hi and welcome to the forums!

The way I’d do it is indeed to add a catch-all show rule, though the implementation is a bit convoluted:

// Element function for sequences
#let sequence = [].func()

// Convert content to an array of its children
#let to-children(cnt) = {
  let inner(content) = {
    if type(content) in (str, symbol) {
      str(content).clusters().map(char => [#char])
    } else if content.func() == sequence {
      content.children.map(inner)
    } else if content.func() == text {
      inner(content.text)
    } else if content.func() == math.equation {
      inner(content.body)
    } else {
      (content,)
    }
  }
  return inner(cnt).flatten()
}


#show: it => {
  let temp = to-children(it)
  temp = temp.map(i => {
    let test = i.func()
    if i.func() == heading {
      return (i, lorem(50))
    }
    return i
  }).flatten()
  
  sequence(temp)
  
}


= one

= two

#[
  also works for a nested heading
  = three
]

If you have a large document there might be some performance issues, but I didn’t run into any issues while testing.

I do aknowledge that this solution is quite ugly, so if anyone knows a better way i’d be happy to hear about it