philwilson.org

a geek commodity

Textile your textareas with Greasemonkey

March 11th, 2005 by Phil

First of all, the link to the script: Textile your textareas with pure JavaScript.

Roberto De Almeida has posted a Greasemonkey script that makes all textareas textilable which works by injecting a button after your textarea which sends its contents off to his public PyTextile service and then replaces your contents with the parsed results, which means that although you have the full power of the latest version of PyTextile at your fingertips, it can be a little slow to respond.

But of course, Textile has been ported to JavaScript, so here’s a script which does the Textile transformation locally. It’s more limited than Roberto’s version, but still covers most of what you might want to do, like headings, lists, images, text-styling (bold and so on), but no tables and the more complex elements.

It’s based around Roberto’s script and uses Jeff Minard’s SuperTextile for the actual transormation. There’s currently something slightly wrong with it as it sometimes takes a few seconds to run through the final regexes, but I’ll probably just live with it.

| 9 Comments »

9 Responses

  1. This guy has an interesting comment on your textile stuff – namely that rework is next to impossible.

    Do you think it would be useful to inject a second textarea that you put your textile stuff in that updates the original text area with the html-ed text?

    Still won’t help you after you’ve hit post but it might be better than now.

    Posted by Gareth on March 15th, 2005 at 8:38 am
  2. I’m the griper Gareth references.

    Dual textareas, one for input, the other for the output, would help things somewhat. More compact would be to have a button that toggles between the transformed and untransformed text. However, I’m not sure it would be enough better to make it worthwhile for my sloppy and impatient self.

    What might be cool is to store the original text with some persistance and have a button for recovering it.
    If it persisted within a browswer session, it would be useful for thos e situations when I’m making a one-off entry in some system I have no control over (like this one), that I might want to preview, but I’m unlikely and/or unable to return to later and edit.

    If it persisted across browswer sessions, that would open it to a wider range of uses. From my point of view, I’m not sure how much utility it adds, since I don’t enter much text into systems I don’t control that I might want to return to and edit later. On the otherhand, someone using Blogger might.

    I don’t know much about javascript, but as I recall, its possible to do something like this as far as storing the text(I think SquirrelMail uses it to store drafts).

    Ideally the Greasemonkey script would have some context awareness and only present the cached source-text relevant to the form in question.

    This could be accomplished a few ways.

    1) URL matching, but URLs can change.
    2) Hostname matching
    3) Matching of the contents of the textarea with a transformed version of the cached text (with allowances for differences in whitespace & captitalization).

    #3 is probably the highest precision.

    Posted by eas on March 15th, 2005 at 4:15 pm
  3. Well, let’s not get carried away :)

    You’re right though, the ability to keep editing the original textile text would be really good (especially seeing as I’ve just fallen foul of it myself!).

    I’ll definitely give it a go.

    Posted by Pip on March 16th, 2005 at 8:39 pm
  4. I ran into a bit of a problem running this on my old Textile-formatted blog entires (which mix in non-markup parentheses and HTML links, along with the textile codes), so I made a small fix to the links RegExps, described here: http://corky.net/dotan/log/2005/03/javascript-textile-follow-up.html

    Posted by Dotan on March 17th, 2005 at 4:22 pm
  5. I’ve extended this to translate Textile to BBCode or MediaWiki markup as well as HTML. It’s still only one way, however. Here it be: Lingua Franca.

    Posted by Mike Sugarbaker on June 24th, 2005 at 12:43 am
  6. That’s awesome!

    I have a version which keeps the original text, I’ll clean it up and update the main script.

    Posted by Pip on June 24th, 2005 at 7:41 am
  7. Hello, Phil!

    I just posted a small rewrite of Jeff Mainard’s script, do you believe there interest in rewriting the greasemonkey script?

    My post explaining what I did is here:
    http://jroller.com/page/dukejeffrie/?anchor=textile_in_javascript

    Posted by Tiago Silveira on November 7th, 2005 at 10:28 pm
  8. Hi Tiago, thanks for this. I’ve been meaning to release a more powerful rewrite of the greasemonkey script for about six months now, hopefully this should prompt me into it; I’ll try and get a new version out in the next few days.

    Posted by Pip on November 7th, 2005 at 10:46 pm
  9. *commen?*

    should be bold, no?

    Posted by Santa on April 26th, 2007 at 10:13 pm

Leave a Comment




Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.