Agile Web Development

Build it. Launch it. Love it.

Highlight

Highlight

Highlight is a simple syntax highlighting plugin for Ruby on Rails. It’s basically a wrapper around the python project pygments (http://pygments.org/) that support various languages.

The plugin adds a new method available in all templates:

  highlight(language, code)

where language can be either a symbol or a string (most file extensions should work for example)

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

  /tmp/highlight_1225993290.70882

Since writing that file, passing its contents on to pygments 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.

  * 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)

Acknowledgements

The actual highlighting is done by Pygments (http://pygments.org/).

Vitals

Home http://simplabs.com/#projects
Repository http://github.com/marcoow/highlight/tree/master
License Rails' (MIT)
Tags Tag_red
Rating (6 votes)
Owner Marco Otte-Witte
Created 20 November 2008

Comments

Add a comment