Actually as my friend Aevyz reminded me, Markdown parses HTML in it.
You won’t need to change your parser. The quickest path to solve that I could think of is this:
<div dir="rtl">
سلام دنیا
مرحبا العالم
שלום בעולם
ہیلو دنیا
</div>
So you need to add literally two lines to turn a whole document or an arbitrary section of it into RTL. It will be more compatible than an own script.