Syntax highlighting of code in Radiant CMS
Posted by tom July 23rd, 2006
Inspired by some code snippets on the Trac website of Radiant CMS I wrote a Radiant CMS behaviour which will automagically do syntax highlighting.
I’m using it on my site with a stylesheet loosly based on the Ruby Lang Redesign 2005 TextMate Theme
The behaviour uses Syntax ofcourse! Syntax can be installed as a gem. The easiest way to get it is via Subversion$ cd vendor/plugins $ svn co http://svn.cortauri.net/rails_plugins/code_behaviorIt looks like this:
require “xmlrpc/client”
- Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( “localhost”, ”/”, 8080 )
- Call the xmlrpc server to try and add two numbers
begin
result = server.call(“api.add”, 5, 3)
puts “Sum of 5 & 3: #{result}”
rescue XMLRPC::FaultException => e
puts “Error:”
puts e.faultCode
puts e.faultString
end
# Call the xmlrpc server to try and divide two numbers
begin
result = server.call(“api.div”, 5, 0)
puts “Division of 5 & 0: #{result}”
rescue XMLRPC::FaultException => e
puts “Error:”
puts e.faultCode
puts e.faultString
end
The CSS you need for this is as follows:
pre.code_ruby {
background-color: #0D151E;
color: #fff;
padding: 10px 10px 10px 10px;
margin: 4px 0px;
font-size: 1.1em;
overflow: auto;
}
/* Syntax highlighting */
pre.code_ruby .normal {}
pre.code_ruby .comment { color: #428BDD; font-style: italic; }
pre.code_ruby .keyword { color: #F8BB00; }
pre.code_ruby .method { color: #077; }
pre.code_ruby .class { color: #fff; }
pre.code_ruby .module { color: #050; }
pre.code_ruby .punct { color: #FFF; }
pre.code_ruby .symbol { color: #B53B3C; }
pre.code_ruby .string { color: #1DC116; }
pre.code_ruby .char { color: #F07; }
pre.code_ruby .ident { color: #fff; }
pre.code_ruby .constant { color: #8AA6C1; }
pre.code_ruby .regex { color: #CA4344; }
pre.code_ruby .number { color: #EDDD3D; }
pre.code_ruby .attribute { color: #5bb; }
pre.code_ruby .global { color: #7FB; }
pre.code_ruby .expr { color: #227; }
pre.code_ruby .escape { color: #1C6A21; }
Support for multiple languages is supported with Syntax, see the Syntax website. If anyone has created more languages, please let me know.

Leave a Reply