#Get Heading Text for Page Header

14 messages · Page 1 of 1 (latest)

woeful birch
#

When trying to get the current chapter im in for displaying in the page header,

let headings = query(
  selector(heading.where(level: 1)).before(here())
)

i get my custom outline header completely styled. is there a way to extract only the text inside an element or to strip an element of all styling leaving only the text?

noble swift
#

You can get the body of the heading, though it won't contain the number. You could then in the same step also display the value of the heading counter at the respective heading location:

let headings = query(...).map(it => {
  let num = if it.numbering != none {
    numbering(it.numbering, ..counter(heading).at(it.location()))
    sym.space
  }
  num + it.body
})

However, you probably don't need to reinvent the wheel and should check out the hydra package

woeful birch
#

Right, that’s what I’m doing, since i don’t need the number. However since it is a custom heading for the outline (it is actually just the title param overwritten) the body of the outline heading contains all the styling and it’s own body (including a line below the heading). For the other headings the body is simply (TEXT: „[…]“) - even though they are customized as well.

noble swift
#

how are you passing the outline title parameter?

woeful birch
#

Don‘t have it open at this moment but iirc
via set outline and the passing in a content block to title

noble swift
#

Does that content block include a heading itself, as in title: [= Outline] ? If yes, then it may be the case that the body of the outline heading is another heading element

woeful birch
#

I’ll check again tomorrow. But iirc it does not. It is only styled #text with some spacing and a #line.

noble swift
#

oh I see, the line and the styles are in fact part of the body then

woeful birch
#

Hmm I see, so there is no way to „strip“ it then - to only extract the text?
Interestingly enough my normal level 1 headings also have this line but it does not appear in the body with the above query I posted..

noble swift
#

I assume that you style your other headings via a show rule, with which the line is then not added to the body. Maybe it would be best to also use a show rule for the outline heading like

show outline: it => {
  show heading: ...
  it
}
woeful birch
#

Yes i think for headings I use

show headings.where(level: 1, numbering: „1.1“): ….

Interesting approach..what is the understanding behind that behavior, that I am missing? will definitely try that out and let you know. Thanks 🙂

noble swift
#

Hmm I see, so there is no way to „strip“ it then - to only extract the text?
You can define a function that can convert content to string with something like this. though it's not always working perfectly. It may be fine in your case though

#

what is the understanding behind that behavior, that I am missing?
Show rules don't change the element itself (as in the body), but only how it should look given the already existing data. When you add the line or styles to the heading manually, they become an actual part of its body and not just of its look

woeful birch
#

Those sound like two good solutions. I think the former you mentioned might be „cleaner“, so will try that first. If not, a custom function should do the job fine, since this is one of the only cases, and I know what the repr of the outline title is.

Thanks, will keep you posted.