Inserting BiDi support tags in online Textareas

This post will only be relevant to readers of right-to-left languages, and to developers who develop for such languages. As such, my next post will be a translation of this one into Hebrew.
A bit over a year ago, a friend of mine wrote about embedded unicode right-to-left and left-to-right characters in a flow of text. In a nutshell, when writing text that contains both LTR characters (like English) and RTL characters (like Hebrew), the flow of the text can wind up messed up. Here’s an example:

The (proper) solution to this conundrum is this: wrap your text, which you want flowing in the opposite direction from it’s encapsulating element, in the unicode characters for left-to-right embedding (or right-to-left embedding), and the Pop Directional Formatting character. For further reading, go here.

Back when Liron wrote that post of his, I thought it would be a nice little project to tackle – write a Firefox plugin or Greasemonkey user-script that allows you to encapsulate your text in these characters, for the sake of all those who will follow and read it. I have since then become familiar – and very fond of – bookmarklets. I think a bookmarklet is the best way to distribute the solution to this problem, because it’s lightweight, easy to install and modify, and (at least in theory) cross browser.

Coming to tackle this issue, I knew I needed to insert a string of characters in front of and after the selected text in a textarea. Where have I seen this done before?… Oh, right, right here in WordPress, when I want to make text I’m writing bold or italicized.
So I went about finding the Javascript behind that functionality (it’s the function edInsertTag), and I pulled out of it the bits that are relevant to this situation, and to Firefox.

With no further ado, I present to you RTL and LTR.

Simply drag those two links to your bookmark toolbar (I actually have a bookmark folder just for bookmarklets), and next time you’re writing bidirectional text, select the wrongly-flowing part, and align it properly.
You can try them out here:

I’d be happy to get feedback on these bookmarklets. They’ve only been tested in Firefox, and I think they will not work in other browsers, seeing how I only used one of the three cross-browser-compatibility parts of the wordpress JS I cannibalized. If they do work in other browsers, or do not work as expected in Firefox, please let me know.

2 Comments on "Inserting BiDi support tags in online Textareas"

  1. Not working for me, Kubuntu 9.04 with Firefox 3.0. I do not have any fancy Javascript extensions installed.

  2. Doesn’t work for me :/

Leave a Reply to Eyal Sela Cancel reply

Your email address will not be published.


*