Enabling syntax highlighting in Blogger pages
Blocks of source code don't always render very well in blogger if you just simply use the <blockquote> HTML tag, they just kind of melt in and are hardly distinguishable from the rest of the text.
Thanks to Alex Gorbatchev, it's easy to make it better. Here are the steps:
- Go to http://code.google.com/p/syntaxhighlighter/ and download the latest version of the scripts. As of now the latest package is http://syntaxhighlighter.googlecode.com/files/SyntaxHighlighter_1.5.1.rar
- Now you need to find a web server where to host those files. Once you've found it, you need to copy the files to the DocumentRoot:
cd /tmp unrar x SyntaxHighlighter_1.5.1.rar cd $docroot mkdir SyntaxHighlighter cd SyntaxHighlighter cp -r /tmp/dp.SyntaxHighlighter/S* .
- Go to the Layout tab on you Blogger console and choose "Edit HTML".
- Right after <Head> insert the following lines:
<link href='http://yourwebsite.org/SyntaxHighlighter/Styles/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shCore.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushCSharp.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushXml.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushCss.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushJScript.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushSql.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushCpp.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushJava.js'/> <script language='javascript' src='http://yourwebsite.org/SyntaxHighlighter/Scripts/shBrushRuby.js'/>
- Right before </body> insert the following lines:
<script language='javascript'> dp.SyntaxHighlighter.ClipboardSwf = 'http://yourwebsite.org/SyntaxHighlighter/Scripts/clipboard.swf'; dp.SyntaxHighlighter.BloggerMode(); dp.SyntaxHighlighter.HighlightAll('code'); </script>
<pre name="code" class="html:nogutter:nocontrols">and
</pre>Please go to Alex's documentation to find the list of languages that are supported and which class to apply.
