views:

589

answers:

5

I'm looking for a general purpose syntax highling 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

+11  A: 

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 loosing it's 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:

Koistya Navin
+1  A: 

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

http://code.google.com/p/syntaxhighlighter/

Edit: Actually I believe it is Prettify:

http://code.google.com/p/google-code-prettify/

BobbyShaftoe
A: 

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.

Joey
A: 

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

Vinay
A: 

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

Sam Saffron