Avoiding long polling

July 26, 2009 2 comments

Right from Twitter to Google Wave, real time information streaming via the browser seems to be the most “happening” thing on the web arena currently. However, feeding real time information as and when it is available to an user using your web application is not as straight forward as it is on a desktop environment.

Codemirror – javascript syntax highlighting

July 22, 2009 No comments yet

CodeMirror is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a few). This tutorial will show you how to implement CodeMirror on your site, there is a great article written by the author of this library here on how it works under the hood.

Installation

Download the latest version from the CodeMirror website. As of today, it is version 0.62. After you unzip it you will see 3 directories – js, css and contrib. contrib holds parsers that other people have written such as the lua, python and PHP. css holds the color schemes for syntax highlighting and js contains the necessary scripts for CodeMirror to run.

Basic Usage

If we have a textarea with an id of code that we wanted to turn into a CodeMirror editor with a MirrorFrame(more on this later) then we would use the code below. Note that we need to specify where the parserfiles and stylesheets for the particular type of syntax (in this case javascript) are located.

  var textarea = document.getElementById('code');