Dec 24, 2007

Ruby Syntax Highlighting On Blogger

It turns out that creating syntax highlighted source in blogger is not difficult even if it's not convenient

The first step is to find an application that can syntax highlight and convert your code to HTML. I choose to hack together a quick little script on top of the Syntax library (the code's below)
require 'rubygems'
require 'syntax/convertors/html'
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
puts convertor.convert(File.read(ARGV[0]))
Now when ever you want to make a post just choose 'Edit Html' in the composer and insert the output from your formatter application.

Depending on on your formatter you may need to add it's CSS to your Blogger template.

1 comment:

Unknown said...

Hi,
you may also be interested in this post I've made on my blog. It's some kind of generic syntax highlighting which works quite well.