How to apply dropcap to the first paragraph after a heading?

This code seems like it should work, but instead it applies the dropcap function to “it” instead of the paragraph text. Where am I going wrong?

This example is modified from the closest thing I could find on this forum for what I am trying to do.

#import "@preview/droplet:0.3.1": dropcap
#let head-par-counter = counter("heading-par")

#show heading: it => {
  head-par-counter.update(0)
  it
  head-par-counter.update(it.level)
}

#show par: it => context {
  head-par-counter.update(0)

  // Note: context is frozen at the start of the context block,
  // so .get() below happens before the .update(0) above
  let current-level = head-par-counter.get().first()
  if current-level > 0 {
    dropcap()[it]
  } else {
    it
  }
}

// Sample usage:
#set page(width: 200pt, height: auto, margin: 1cm)
Hello world, this paragraph is not affected

= First

Hello world, this paragraph is replaced by the "it" argument to the drop cap function. I want it to apply the dropcap function to the "H" at the beginning of the paragraph. 

== Second

Hello world, this one is the same as the first. 

Not affected here! (Not the first paragraph, and this is what I want)

At dropcap()[it] the it is inside markup mode, you have to either write dropcap()[#it] (hash sign to switch to code mode) or dropcap(it). Additionally, I think (I didn’t test because I’m on my phone) you need to use it.body.

Or just dropcap[#it].

Yes.

1 Like

Thank you! It seems to work in both of these ways:

#show par: it => context {
  head-par-counter.update(0)

  let current-level = head-par-counter.get().first()
  if current-level > 0 {
    dropcap()[#it.body]
  } else {
    it
  }
}

and

#show par: it => context {
  head-par-counter.update(0)

  let current-level = head-par-counter.get().first()
  if current-level > 0 {
    dropcap(it.body)
  } else {
    it
  }
}