It is tracked in the templater object, though it's not exposed externally. You'd have to extend the templater if you wanted to do that.
Strictly speaking, the ideal way to change the behavior of rendering is based on the context we setup the BB code renderer with. For example, thread_preview renders with "post:thread_preview" as the context. This is passed into XF\Entity\Post::getBbCodeRenderOptions()
to setup the options/data for the BB code renderer.
So you could check the context there and adjust the options you pass to the BB code renderer (and then have your callback change behavior based on some sort of flag).
The context is also passed into the BB code rule set, so I think you can also access the getRules()
method on the renderer object (which then exposes getContext
and getSubContext
).