How to query contents between headings?

58 views Asked by At

Is selector in Typst able to select contents between headings? I have three headings, eg: Test1, Test2 and Test3, how to extract/query the contents between these headings?

The result is 10 words generated by #lorem(10), and the content "Hello World. \n Hello Again.", and the content "This is test3 \nThis is test3 too".

The below query can only select headings itself, and I don't know how to select/extract the contents between headings?

= Heading

#locate(loc => {
  let elems = query(
    selector(heading.where(level: 2)).after(loc),
    loc
  )
  if elems.len() > 0 {
    elems.last()
  } else {
    [Test]
  }
})

== Test1
#lorem(10)

== Test2
Hello World. \
Hello Again.

== Test3
This is test3 \
This is test3 too
0

There are 0 answers