Fix markdown rendering with inline maths

The mistune 'text' regex was capturing into math expressions in some
cases. The fix was to modify it to stop at a $ sign, giving the inline
math regex a chance to capture that.

Closes gh-6724