until nil {

CodeRay textfilter for Typo

18 Sep 2008

( Update! 2010-08-20 ). This blog is not powered by Typo anymore, while Typo has since evolved for the better, I choose now to work with statically generated html with the help of Jekyll. I leave this post here anyway, for those who might need it for references.

How could I build a tech blog without proper code block highlighting?

Thats what I realised when I saw Typo coming a bit short in term of syntax highlighting. Not that there isn't one, but the Syntax textfilter included with the app is missing some languages definition in its arsenal to make it a decent choice, unless someone would only write Ruby, XML and YAML blocks in its blog. There is alway the prospect of writing a language module for Syntax but lets not rely on this for now.

The Odds:

I did a bit of research, and found three other syntax highlighting systems that suited Typo, with no coding or a minimum of coding required:

  • tmcode, already built into Typo, assure the loading of the css necessary to display code html generated by the wonderfull Textmate OSX text editor.
    Pros: very esthetic result, fast load time, support lots of languages
    Cons: you need a Mac with Textmate, not a true "Markup and Publish" solution.
  • Ultraviolet, syntax highlighting library built on top of Textpow, which is built on top of Oniguruma-Ruby, which is built on top of Oniguruma. You get the option of using either Radiograph or tm_syntax_hightlighting as your Rails interface for Ultraviolet.
    Pros: uses Textmate highlighting making it an esthetic choice, decent language support
    Cons: dependency chain has many obstacles, not very fast,
  • CodeRay, syntax highlighting gem built entirely in Ruby
    Pros: easy gem installation, esthetically ok
    Cons: language support not that extensive.

The Test:

I tried hard to make Ultraviolet work... no problem on my development machine... but the hosted server never got to compile the first dependency, Oniguruma, adequately. So I jumped off the UV boat a bit depressed after a couple of days of hard labor. It was my first choice mainly for the large language palette, ignoring the speed issue which could have backlashed after regular usage.

So I turned to tmcode and Coderay. tmcode wasn't a bad option after all, giving the speed gain allowed by not having to process anything on the server at display time... and I happen to be both a Mac lover and a Textmate lover so there wouldn't be much pain in using this solution. But still, I wanted something I could use from any computer, so I embarked the CodeRay installation anyway... my language support of choice is not there at the moment, but the developper has a new version coming late september, which could change that consideration, and at worst, I could end up coding the languages support I need myself.

CodeRay has hit the place!

Installation is straightforward:

gem install coderay

Then what?
Typo has an ideal mechanism to integrate with CodeRay, called textfilters.
You can code one yourself by reading the Typo documentation on the subject: http://scottstuff.net/blog/articles/2005/08/23/introduction-to-typo-filters

which I did...
so you also have the option of using my implementation of CodeRay as a textfilter called CodeView.
Here it is: http://software.spiralix.org/typo/textfilter/typo_textfilter_codeview.zip
place this whole folder, unzipped, inside the vendor/plugins/ directory of your Typo installation and you are ready to go.
To get usage information, loggin to your Typo admin panel, under Settings->TextFilters you will find your CodeView macro with its help link to the far right of the page.

blog comments powered by Disqus

}

Older Posts... Blog powered by Jekyll.
Built using Liquid, RedCloth, Pygments and Blueprint.

Copyright © 2008-2010 Louis-Philippe Perron