lice! : Typo & Coderay

Typo & Coderay

Well I’ve decided to play with that Typo thing, nice very nice to be exact. Now I flipped through the admin settings and found that even syntax highlight for code is supported, even nicer, so the used highlighter is somewhat limited and as odds are a friend of mine (named murphy) and myself worked on syntax highlighting a good while ago with very good results and I happen to know that there is a ruby offspring of said efforts (ported and extended by murphy) that is still maintained. To cut a long story short, I am too curious about how things work to not make a Typo plugin to support Coderay and well here we go I did it, using the provided `` plugin as a base. Here a little help how to set it up. 0. Why the hassle? —————— There are a number of reasons, first would be cause I wanted to see how extendable Typo is while that might not be of any interest for someone else there are still other reasons. The first would be that Coderay simply provides more languages then the original shipped syntax highlighter. For example C (and deviates), html, or more important rhtml. Second would be the simple fact that Coderay is very damn precise about highlighting, while that don’t matters for ‘easy’ languages like C that are very strict in their syntax it **does** matter for languages like ruby. Here a little example about how good it works (from the plugin help): class MyClass def MyFun “abcde #{(“#{my_int_arg} times”)*my_int_arg }” end end Note the nested code blocks in the string, also regular expressions are matched very good. Third is that it is just very fast compared to other highlighters, while it don’t matters for a one line code sample it can matter when codes get bigger or more. 1. Get coderay ————– A gem is provided so it is not a big problem installation is simple: gem install coderay Which should install Coderay and all it’s dependencies. Thanks to the great ruby gems systems it’s not hard eh? the rest is neither so lets go on. 2. Set up Typo ————– This is not all that easy but it stays simple if you’ve a fundamental gasp about the file system of your operating system. To begin with download the [controller](http://heinz.licenser.de/coderay_controller.rb.bz2) (it is provided as a attachment) I assume you’re running under a *nix shell in the example so here we go: wget http://heinz.licenser.de/coderay_controller.rb.bz2 You can also just download it via browser and later upload it to your side but well I explain how I would do it not all possible ways so bear with me ;). Okay next step is to copy the controller to the right place. Typo is so nice to make it easy to do the installation of plugins, so having the file in the right place will be enough to have it running in the first place. The path for text-filters is: `components/plugins/textfilters/` assuming you’re into the typo root directory. Also I assume you downloaded the controller into your home directoy. Okay here step by step what to do: cd cp ~/coderay_controller.rb components/plugins/textfilters/ Tada, that part done if you’re running the installation under another user you may want to adjust the ownership (unless you understand and already know how to do that you most likely don’t have to worry about it). Okay restart typo and oh happy joy you can post code! typo restart 3. Syntax sugar ————— Now you’ve an working Coderay highlighter (hopefully) but it don’t highlights much unless you put the CSS styles nicely. Easiest way is to use the CSS files Coderay already provides all you’ve to do will be: cd coderay_stylesheet >> public/stylesheets/administration.css coderay_stylesheet >> public/stylesheets/user.css And all looks nice and shiny! Feel free to adjust the styles to how you like it or just leave them how we liked it ;) There we go all is done! Hopefully at least this worked just fine for me. Non the less if you run over a problem let me know about it.

Posted by Heinz N. 'Licenser' Gies Sat, 29 Jul 2006 17:15:00 GMT


Trackbacks

Use the following link to trackback from your own site:
http://blog.licenser.net/trackbacks?article_id=2