Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 218
aussiegeek Avatar asked Mar 27 '09 09:03

aussiegeek


People also ask

What is use of syntax highlighting?

Syntax highlighting is one strategy to improve the readability and context of the text; especially for code that spans several pages. The reader can easily ignore large sections of comments or code, depending on what they are looking for. Syntax highlighting also helps programmers find errors in their program.

What is syntax highlighting in JavaScript?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.

How do I enable syntax highlighting?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.


2 Answers

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:

  • Syntax Highlighting for Ruby Made Very Easy
  • Syntax highlighting in Ruby
like image 92
Konstantin Tarkus Avatar answered Sep 18 '22 13:09

Konstantin Tarkus


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/

like image 35
BobbyShaftoe Avatar answered Sep 19 '22 13:09

BobbyShaftoe