RTL in Markdown

MarkdownRight to-Left

Markdown Problem Overview


Is there any existing addon spec for markdown that includes support for RTL languages?

What I'm hoping for is something like

This paragraph is left to right
<- This paragraph is right to left

Or something... I can tweak my parser to handle this but I want to make sure it doesn't exist already.

Markdown Solutions


Solution 1 - Markdown

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.

Solution 2 - Markdown

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 &#x202b; (RIGHT-TO-LEFT EMBEDDING) in the beginning of a paragraph does control the direction of this paragraph (auto-reset on <br/> or empty line):

&#x202b;test מה זה? YES<br/>
test1 מה זה? NO
test2 מה זה? NO

&#x202b;test1 מה זה? YES
test2 מה זה? YES

> ‫test מה זה? YES
test1 מה זה? NO test2 מה זה? NO

> ‫test1 מה זה? YES test2 מה זה? YES

Solution 3 - 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

Solution 4 - Markdown

I don't find anything in markdown standard for bidi texts. I use my own editor : rtlmd

Solution 5 - Markdown

Just use dir="auto" like the below example and it will work as you wanted:

 <div dir="auto">
                با استفاده از attribute dir با مقدار auto در HTML می تونید به طور خودکار RTL رو هم داشته باشید.
  </div>

Solution 6 - Markdown

מעניין. עכשיו אני רואה שבעצם יש גם לאתר הזה פה תמיכה בעברית וכתיבה מימין לשמאל. הבעיה היא שזה כותב טוב, אבל בתרגום בתיבה למטה שמציגה כמו שזה אמור להראות זה לא עובד טוב.

The above paragraph was written in Hebrew RTL and was displayed correctly in the input box but not in the preview one. However, there was no support for mixing - having one paragraph RTL and another one LTR. Seems someone needs to port the above Hebrew support in Markdown also for MarkdownSharp, SO's version. Shouldn't be too hard.

Solution 7 - Markdown

you can use:

<div align="right">
   این متن test است
</div>


or:

<div dir="auto" align="right">
   این متن test است
</div>


or (recommended):

<div dir="auto">
   این متن test است
</div>

Solution 8 - Markdown

You can simply add everything between span tags like below:

<span dir="rtl" align="right">
      این یک test است
</span>

You may want to check this link to see an example in action.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKarimView Question on Stackoverflow
Solution 1 - MarkdownMakan TayebiView Answer on Stackoverflow
Solution 2 - MarkdownAlex CohnView Answer on Stackoverflow
Solution 3 - MarkdownKajMagnusView Answer on Stackoverflow
Solution 4 - MarkdownDariush AbbasiView Answer on Stackoverflow
Solution 5 - MarkdownSeyyedKhandonView Answer on Stackoverflow
Solution 6 - MarkdownAviView Answer on Stackoverflow
Solution 7 - MarkdownAli ShariatianView Answer on Stackoverflow
Solution 8 - MarkdownKooroshView Answer on Stackoverflow