Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Syntax Higlighting plugin for Ruby on Rails

tree: cb636a6135

Fetching latest commit…

Cannot retrieve the latest commit at this time



Highlight is a simple syntax highlighting plugin for Ruby on Rails. It's basically a wrapper around the popular highlighter that's written in Python and supports a huge number of languages.

See the API docs at

Highlight provides a new method that's available in views:

highlight(language, code = nil, &block)

language may be either a Symbolor a String (see supported languages below). The code can be passed either as a string or inside a block, e.g.:

highlight(:ruby, 'class Test; end')


highlight(:ruby) do
    class Test

To perform the highlighting, the code is first written to a file in /tmp, e.g.:


This file is the passed to pygments that returns the HTML and so on…

Since writing that file, passing its contents on to pygments, retrieve the result etc. takes a while, all highlighted source code should be cached of course, e.g.:

<% cache do %>
  <%= highlight(:ruby, 'class Test; end') -%>
<% end %>

Supported Languages

The following languages are supported. All of the paranthesized identifiers may be used as parameters for highlight to denote the language the source code to highlight is written in (use either Symbols or Strings).

* Actionscript (as, as3, actionscript)
* Applescript (applescript)
* bash (bash, sh)
* C (c, h)
* Clojure (clojure)
* C++ (c++, cpp, hpp)
* C# (c#, csharp, cs)
* CSS (css)
* diff (diff)
* Dylan (dylan)
* Erlang (erlang, erl, er)
* HTML (html, htm)
* Java (java)
* JavaScript (javascript, js, jscript)
* JSP (jsp)
* Make (make, basemake, makefile)
* Objective-C (objective-c)
* OCaml (ocaml)
* Perl (perl, pl)
* PHP (php)
* Python (python, (py)
* RHTML (erb, rhtml)
* Ruby (ruby, rb)
* Scala (scala)
* Scheme (scheme)
* Smalltalk (smalltalk)
* Smarty (smarty)
* SQL (sql)
* XML (xml, xsd)
* XSLT (xslt)
* YAML (yaml, yml)


Installation is as easy as (for Rails > 2.1):

./script/plugin install

The hightlight.css stylesheet that contains the neccessary style definitions should be copied to your public/stylesheets directory automagically.

If you are on Rails < 2.1, do this from your RAILS_ROOT

git clone vendor/plugins/highlight

In this case you would have to copy the hightlight.css stylesheets manually from vendor/plugins/highlight/assets/stylesheets/.

If you don't have python and pygments installed, you will need that too. For instructions on installing pygments, refer to

TODOs/ future plans

At the moment there are neither TODOs nor future plans. If you want ot suggest any, do so at


Copyright © 2008-2010 Marco Otte-Witte (, released under the MIT license


The actual highlighting is done by Pygments (

Something went wrong with that request. Please try again.