Showing posts with label Blogger. Show all posts
Showing posts with label Blogger. Show all posts

Sunday, October 21, 2007

Source code high-light in Blogger

I researched how to use source code high-light in Blogger. I found a way with google-code-prettify from here. This way runs on Javascript, so we don't need to install some engine to Blogger.

Download google-code-prettify


Donwload the archive file from here. After that, fetch both of JS file and CSS file from the archive.

Embed the content of files


You may embed source code of these files, but it's easy to use HTML/JavaScript widget. Embed source code with comment & script tag as the following:

<script type="text/javascript"><!--

// Paste prettify.js code here!! //

--></script>

<style type="text/css">

// Paste prettify.css code here!! //

</style>


Edit your template


To reflect this change to your blog, edit your template as the following:

- <body>
+ <body onload='prettyPrint()'>

In a summary, activate the Javascript in body of your blog.

How to use?


Write your code within <pre class="prettyprint"></pre>.

Conclusion


This way is very good for us, but you may go to trouble when you use a HTML tag, because such descriptions is handled as natural HTML tags. Therefore, when we use "inequality sign", we may go to trouble, too.

Anyway we can't write souce code in blogger, as well as bbcode. Therefore, "better than nothing". Do try it. ;)