Module: Simplabs::Highlight
- Defined in:
- lib/simplabs/highlight.rb,
lib/simplabs/highlight/railtie.rb,
lib/simplabs/highlight/pygments_wrapper.rb
Overview
Highlight is a simple syntax highlighting plugin for Ruby on Rails. It's basically a wrapper around the popular pygments.org highlighter that's written in Python and supports an impressive number of languages. If pygments is installed on the machine and in the PATH, that binary is used, otherwise the plugin falls back to the web API at (pygments.simplabs.com/), created by Trevor Turk.
Supported Languages
The following languages are supported. All of the paranthesized identifiers may be used as parameters for the highlight method 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)
-
NASM (nasm, asm)
-
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)
Defined Under Namespace
Modules: ViewMethods Classes: PygmentsWrapper, Railtie
Constant Summary
- SUPPORTED_LANGUAGES =
{ :as => ['as', 'as3', 'actionscript'], :applescript => ['applescript'], :bash => ['bash', 'sh'], :c => ['c', 'h'], :clojure => ['clojure'], :cpp => ['c++', 'cpp', 'hpp'], :csharp => ['c#', 'csharp', 'cs'], :css => ['css'], :diff => ['diff'], :dylan => ['dylan'], :erlang => ['erlang'], :html => ['html', 'htm'], :java => ['java'], :js => ['javascript', 'js', 'jscript'], :jsp => ['jsp'], :make => ['make', 'basemake', 'makefile'], :nasm => ['nasm', 'asm'], :objective-c' => ['objective-c'], :ocaml => ['ocaml'], :perl => ['perl', 'pl'], :php => ['php'], :python => ['python', 'py'], :rhtml => ['erb', 'rhtml'], :ruby => ['ruby', 'rb'], :scala => ['scala'], :scheme => ['scheme'], :smallralk => ['smalltalk'], :smarty => ['smarty'], :sql => ['sql', 'mysql'], :xml => ['xml', 'xsd'], :xslt => ['xslt'], :yaml => ['yaml', 'yml'] }
- WEB_API_URL =
'http://pygments.simplabs.com/'
Class Method Summary (collapse)
-
+ (String) highlight(language, code)
Highlights the passed code with the appropriate rules according to the specified language.
Class Method Details
+ (String) highlight(language, code)
Highlights the passed code with the appropriate rules according to the specified language.
112 113 114 115 116 117 118 119 120 |
# File 'lib/simplabs/highlight.rb', line 112 def self.highlight(language, code) language = get_language_sym(language) return CGI.escapeHTML(code) unless language if Simplabs::Highlight.use_web_api highlight_with_web_api(language, code) else Simplabs::Highlight::PygmentsWrapper.new(code, language).highlight end end |