Tutorial :Syntax Highlighting


I'm looking for a general purpose syntax highlighting library, to output to html.

It's for use within a ruby app, so a ruby library would be good, but an excellent utility which can be piped in and out of would do

Also needs to guess the appropriate language to highlightsy by itself


HTML/CSS/JavaScript based syntax highlighter solutions are the most popular and work well with different server technologies including Ruby.

  • SyntaxHighlighter (RECOMMENDED) is here to help a developer/coder to post code snippets online with ease and have it look pretty. It's 100% Java Script based and it doesn't care what you have on your server.

  • Syntax highlighting library for various languages at Rubyforge.org. Has built-in support for converting source code to syntax-highlighted HTML.

  • SyntaxHighlighter for WordPress. It allows you to easily post syntax highlighted code all without losing its formatting or making an manual changes.

  • Prettify. A Javascript module and CSS file that allows syntax highlighting of source code snippets in an html page.

  • GeSHi - Generic Syntax Highlighter. GeSHi started as an idea to create a generic syntax highlighter for the phpBB forum system, but has been generalised to this project. GeSHi aims to be a simple but powerful highlighting class, with the following goals: (1) Support for a wide range of popular languages (2) Easy to add a new language for highlighting (3) Highly customisable output formats

  • JUSH is a syntax highlighting component written in JavaScript. It highlights HTML, CSS, JS, PHP and SQL code embedded into each other. Beside syntax highlighting, it provides links to the documentation for all supported languages.

  • SyntaxHighlighter for Windows Live Writer at CodePlex.com (just in case :)

And here a few blog posts on the subject:


Have you looked at Google's syntax highlighter? I believe SO uses it?


Edit: Actually I believe it is Prettify:



Some options are:

  • Syntax - Its really broad, but I think it has some licensing concerns (Syntax is GPL)

  • Coderay - I use this on my blog, it's pretty limited, but is functional

  • Ultraviolet which support a ton of languages (anything that textmate can do)

  • If you are willing to bridge into Python there is Pygments, which supports a ton of languages


Try rouge. It's pure ruby, compatible with pygments, and actively developed.


You might want to take a look at Colorer. It doesn't seem to have bindings for Ruby, but there are for Perl and PHP, maybe one would be able to hack a binding together for Ruby on that basis.


Scintilla can be used with C++ code. I don't know about is there a way to use C++ applications in Ruby.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »