require 'coderay/coderay' class Plugins::Textfilters::CodeRayController < TextFilterPlugin::MacroPre plugin_display_name "CodeRay" plugin_description "Apply syntax highlighting to a code block using CodeRay" def self.help_text %{ You can use `` to include syntax-highlighted code blocks. Example: class Foo def bar "abcde" end end This uses the CodeRay (http://coderay.rubychan.de/) gem. Options: * **lang**. Optional - defaults to `ruby`. Sets the programming language. Currently supported languages are `ruby`, `C`, `Delphi`, `HTML`, `RHTML`, `Nitro-XHTML`. } end def self.macrofilter(controller,content,attrib,params,text="") lang = attrib['lang'] || 'ruby' tokens = CodeRay.scan(text.strip, lang) result = tokens.div(:line_numbers => :table) "#{result}" end end