RTL in Markdown
Here is a JavaScript implementation of Markdown, which (according to the commit comments) adds support for RTL languages, namely Arabic, Hebrew, Syriac, Thaana. And it seems trivially easy to add more languages.
https://github.com/hasenj/showdown/
It's based on Showdown, http://attacklab.net/showdown.
It seems to automatically understand whether or not to render the text from right to left.
Consider this code snippet: (from the very first commit at GitHub)
var p_tag = "<p>";
var rtl_p_tag = "<p style='direction:rtl; text-align: right'>";
// Check for RTL paragraphs: paragraphs that start with a character
// from an RTL script.
// RTL scripts are: Arabic, Hebrew, Syriac, Thaana
// Unicode ranges reference: http://www.ssec.wisc.edu/~tomw/java/unicode.html
var first_char = str.charCodeAt(str.search(/\S/)); //first non-white-space char
if(first_char >= 1424 && first_char <= 1983)
{
p_tag = rtl_p_tag;
}
str = _RunSpanGamut(str);
str = str.replace(/^([ \t]*)/g, p_tag);
Hope this helps,
Magnus
Not exactly markdown, but this is how you can override paragraph direction in StackExchange questions and answers (this method does not work for comments):
add ‫ (RIGHT-TO-LEFT EMBEDDING) in the beginning of a paragraph does control the direction of this paragraph (auto-reset on <br/> or empty line):
‫test מה זה? YES<br/>
test1 מה זה? NO
test2 מה זה? NO
‫test1 מה זה? YES
test2 מה זה? YES
test מה זה? YES
test1 מה זה? NO test2 מה זה? NOtest1 מה זה? YES test2 מה זה? YES
I don't find anything in markdown standard for bidi texts. I use my own editor : rtlmd
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.