> Ideally, the last.

Ha! I might have known.
The reason this is tricky is that TeX is designed to be a macro
expansion language, with control statements embedded in the data.
This makes `going back' difficult.

In the case at issue, you typically won't know what kind of paragraphs
you need to set until after you have seen several, which means that
you need to have stored them as tokens, or possibly better in an
external temporary file. Nothing's impossible, something to think
about over Christmas...