How can I match labels or strings within `where()` using regex?

The reason syntax highlighting is not behaving as you expect is because you are specifying typ as the language and the code in the block is typst, but it is “Code Mode”, not the default “Markup Mode”. Here is the relevant reference page.

To solve directly your problem, swap ```typ with ```typc:

// Provide section numbering for H1/H2/H3 headings. 
  // Exclude Table of Contents, List of {Figures|Tables}, References, etc.
  show heading.where(depth: 1, outlined: true)
   .or(heading.where(depth: 2, outlined: true))
   .or(heading.where(depth: 3, outlined: true)): set heading(numbering: sectionnumbering)

This is pointed out here: How to post in the Questions category

If you need to highlight a code or math mode snippet instead, the language tags typc and typm do that, respectively.

In my opinion, this could be improved since for beginners the distinction between Markup, Code, and Math modes is not obvious.

4 Likes