Code Highlighter Plugin!

Finally! Oh, how I’ve longed for your sweet caress…

Thanks to this how-to, I was able to get syntax highlighting working. It’s super-easy to setup, however I had to do some light digging to get the proper CSS. The one I found was similar to the RubyBlue TextMate theme that I adore.

Here’s a small excerpt (for testing) of the lib/codehighlighter plugin.rb file:

require 'behavior'
require 'syntax/convertors/html'

Behavior::Base.define_tags do
  tag 'code' do |tag|
    lang = tag.attr['lang'] || "ruby"
    convertor = Syntax::Convertors::HTML.for_syntax(lang)
    code = convertor.convert(tag.expand.to_s.strip, false)
    %{#{lang}-code">`#{code}`}
  end
end

And of course, the CSS:

pre.ruby-code {
  background-color: #0d151e;
  color: #fff;
  padding: 10px 10px 10px 10px;
  margin: 4px 0px;
  font-size: 1.1em;
  overflow: auto;
}

/* Syntax highlighting */
pre.ruby-code .normal {
}
pre.ruby-code .comment {
  color: #428bdd;
  font-style: italic;
}
pre.ruby-code .keyword {
  color: #f8bb00;
}
pre.ruby-code .method {
  color: #077;
}
pre.ruby-code .class {
  color: #fff;
}
pre.ruby-code .module {
  color: #050;
}
pre.ruby-code .punct {
  color: #fff;
}
pre.ruby-code .symbol {
  color: #b53b3c;
}
pre.ruby-code .string {
  color: #1dc116;
}
pre.ruby-code .char {
  color: #f07;
}
pre.ruby-code .ident {
  color: #fff;
}
pre.ruby-code .constant {
  color: #8aa6c1;
}
pre.ruby-code .regex {
  color: #ca4344;
}
pre.ruby-code .number {
  color: #eddd3d;
}
pre.ruby-code .attribute {
  color: #5bb;
}
pre.ruby-code .global {
  color: #7fb;
}
pre.ruby-code .expr {
  color: #227;
}
pre.ruby-code .escape {
  color: #1c6a21;
}