Tag plugin in markdown paragraph

I’ve written a new “tag” plugin, which gives the correct output when the tag is in a standalone block-level(I think?) element, e.g. this works fine

Lorem ipsum...

{% my_tag %}

More lorem...

However, when I use the tag inline, I just end up with the HTML output of the tag as text in the paragraph, e.g.

Lorem {% my_tag %} ipsum...

ends up as Lorem <span>tag output</span> ipsum

Is there a way to have markdown preprocessor run before tag expansion, so that the tag output ends up as html in the output?