Thursday, September 4, 2008

Using SyntaxHighlighter with Blogger or Blogspot

I added Syntax Highlighting capabilities to this blog and here it is how i did it. You might need another server where to put your files:

  1. Download SyntaxHighlighter from http://code.google.com/p/syntaxhighlighter/downloads/list.

  2. Add this to your Edit HTML code in Layout:

  3. <script language='javascript' src='http://www.url.com/Scripts/shCore.js'></script>
    <script language='javascript'>
    window.onload = function() {
    dp.SyntaxHighlighter.ClipboardSwf = 'http://www.url.com/Scripts/clipboard.swf';
    dp.SyntaxHighlighter.BloggerMode();
    dp.SyntaxHighlighter.HighlightAll('code');
    }
    </script>
    <link href='http://www.url.com/Styles/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/>

  4. Put the code you want to highlight inside a <pre> tag like this:

  5. <pre name='code' class='language'>
    code;
    </pre>

  6. Make sure you replace the url and also '<' with &lt; if you are using HTML code

  7. Add this to the top of your post:

  8. <script language='javascript' src='http://www.url.com/Scripts/shBrushXml.js'></script>

  9. Replace the script name with the one used for your language.



For more information and language list visit http://code.google.com/p/syntaxhighlighter/w/list.

1 comment:

vivekcis said...

Nice blog. Can this code work with asp as well. I have to make a project in .net and i want to do this operation in .net so i am going to hire .net programmer for this purpose.