Home Platform Services Portfolio Team Blog Contact us
GuruOnRails

Hot Item - Get a FREE Project Estimation! Click here to proceed!
 
Highlighting source code
 
Add to Google Add to Delicious Digg it Add to FURL Add to Newsvine Add to Netscape Add to Reddit Add to STUMBLEUPON Add to MAGNOLIA Add to TECHNORATI

Highlighted source code is must in blog posts if you are going to show some source in your post. Fortunately there is no problems to highlight code in your blog. I will show you the way that perfectly worked for GuruOnRails blog.

It's very simple to implement highlighting Ruby, C++, C#, CSS, Java, JS, PHP, SQL code. This blog uses SyntaxHighlighter. It really lightweight JavaScript implementation of code highlighting.

First of all, you should download SyntaxHighlighter package. It includes all files you need to use(there are JavaScripts, SWF and CSS).

Next you should copy files to approriate fodlers of your site, and include needed ones in your HTML template in HEAD section. For our blog it looks like:

  <%= stylesheet_link_tag "SyntaxHighlighter", :media => "all" %>
  <%= javascript_include_tag 'shCore', 'shBrushRuby', 'shBrushXml', 'shInit'%>
After you do all of these simple steps you are ready to use SyntaxHighlighter. Usage is really simple, just put you code in "pre" tag like shown below and specify "name" and "class" parameters:
   <pre class="rails" name="code">
        Some code goes here
    </pre>

You could see some examples here or there :)

SyntaxHighlighter is great, isn't it?

Konstantin
08 Oct 05:11
0
 
 
Add to Google Add to Delicious Digg it Add to FURL Add to Newsvine Add to Netscape Add to Reddit Add to STUMBLEUPON Add to MAGNOLIA Add to TECHNORATI
Only registered users are allowed to leave comments. Please, register.