views:

219

answers:

3

These days, in any site where they show a code fragments (even in Stackoverflow), the code is nicely wrapped around a GUI element which highlights syntax elements, provides line numbers, etc. I want to show some ruby on rails code in my blog and I want those visual elements in my blog.

How can I accomplish this on my blogger blog?

A: 

Using the links Alex Reitbort provided you can integrate this in your Blogger blog using one of the following tutorials:

http://heisencoder.net/2009/01/adding-syntax-highlighting-to-blogger.html
http://yacoding.blogspot.com/2008/05/how-to-add-syntax-highlight-to-blogger.html
http://abhisanoujam.blogspot.com/2008/12/blogger-syntax-highlighting.html

mensch
I really don't understand your edit. Don't you have better things to do than needlessly nitpicking with formatting until it meets your personal preference?
Josh Stodola
Can't say I like the hostile Edit Summary left by Rich B either. "Don't bother paying attention to the preview or anything..." Nice.
mensch
+2  A: 

Click on "Edit HTML" in Blogger and then insert the following in the <head> section of your HTML:

<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushRuby.js"&gt;&lt;/script&gt; <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shLegacy.js"&gt;&lt;/script&gt;
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css" />
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css" />     <script language="javascript">
window.onload = function () {
    dp.SyntaxHighlighter.ClipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
    dp.SyntaxHighlighter.BloggerMode();
}
</script>

and the following into the <body> wherever you want to put your code:

<pre class="brush: ruby" name="code"># Your Ruby Code</pre>

I've tested this and have a working example of this code.

sfarbota