It is generally easier for the person who knows the code to reduce it enough so that other people can inspect it, than other people who have no knowledge of the code or what’s relevant to the issue reading through a huge codebase. Thus it is considered good form for the person asking to post all relevant code, and indeed that is also part of the question guidelines:
It would be great if you could post the smallest possible code samples that allow people to see what your problem is.
Luckily in this case it’s easy to guess what the problem is—the heading numbering. Adding this single line demonstrates the problem:
#set heading(numbering: "1.")
It seems the set block approach breaks down there, but wrapping in a block still works:
#set heading(numbering: "1.")
#show heading: it => {
block(inset: (left: 8pt * it.level), it)
}
#show par: it => context {
let h = query(selector(heading).before(here())).at(-1, default: none)
if h == none { return it }
block(inset: (left: 8pt * h.level), it)
}
= L1
#lorem(30)
== L2
#lorem(30)
=== L3
#lorem(30)
== L2
#lorem(30)
= L1
#lorem(30)
== L2
#lorem(30)
=== L3
#lorem(30)