Trying out CodeMirror

I was very impressed when I understood what the JavaScript library CodeMirror does for a coding site. I immediately wanted to try it, but I didn't have much of a reason. Last night I got a chance to try the codemirror-rails gem in a rails application. The code is available on github.

The basics for using it in a form are to place your textarea within a div and to style the div to add the border:

<div class="border">
    <textarea name="foo" class="use-cm">
    </textarea>
</div>

Then, use jquery to find the textarea and run it:

$('.use-cm').each(function() {
    var me = $this;
    var cm1 = CodeMirror.fromTextArea(me, {options... });
});

Getting GeSHI Filter to work with my Drupal theme was a bit harder, actually.