Update: I no longer support the use of SyntaxHighligter. I would rather suggest the use of gists provided by GitHub. It is easier to use. Give it a try.
Using SyntaxHighlighter to Show Code Snippets in Blogger
I have found out a way to display code snippets with syntax colouring. There is a very nice yet useful tool consisting of a small set of js and css files: SyntaxHighlighter.
Required files can be found at project site. After downloading files we will need to store them in an online location to refer them from our blog pages. At this point Google Sites proves to be useful. Just create some pages and upload SyntaxHighlighter files. So that we can refer them from blogger pages.
Usage:
Add lines below to blogger page. Just remember to add all brush files you need. For a list of all available brushes see related page.<script type="text/javascript" src="https://sites.google.com/site/your_site_path/scripts/shCore.js"></script> <script type="text/javascript" src="https://sites.google.com/site/your_site_path/scripts/shBrushJScript.js"></script> <link type="text/css" rel="stylesheet" href="https://sites.google.com/site/your_site_path/styles/shCoreDefault.css"/>
After adding required files to your page, next step is to put the content you want to display in syntax colouring. Content to be displayed should be enclosed with HTML pre tags and should be HTML escaped. To easily escape your content you may use any online tools like this one
<pre class="brush: js">// any content function foo() { } </pre>
Code snippets included in this page are also kind of demonstration of the utility.
For updates and further instructions give a visit to official page of the utility.
Comments
Post a Comment