Mathematics extension

I have implemented parsing math inline of $...$ and $$...$$ and I followed mostly how parsing is done for emphasis delimiters, but I’m not really convinced this is the best way to do it. I would in fact expect $...$ and $$....$$ to work a bit like a string with quotes (but would just allow escape with \$).

But looking at pandoc for example, with the following case:

This is a test $$this is a test$

it is generating this:

<p>This is a test <span class="math inline">\($this is a test\)</span></p>

Unlike delimiters, I would expect that a $$ should match an ending $$

I’m not sure how Latex behaves with this. Is this the way it is usually handled?