At last thought I'll clean stuff up a little bit, and also by the way thought of covering up the changes that I made to my blog template for syntax highlighting. Just wanted to keep my changes somewhere, last time forgot to keep a back-up of my working template before editing and had to start all over.
I'll be using the syntax-highlighter to highlight my source-codes in my blog.
Things that are needed for this are:
- Download syntax-highlighter and upload it somewhere in the internet where you have access to. I chose google-pages to host my files.
The main files that need to be uploaded are:- dp.SyntaxHighlighter/Scripts/clipboard.swf
- dp.SyntaxHighlighter/Scripts/shBrushJava.js
- dp.SyntaxHighlighter/Scripts/shCore.js
- dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css
- dp.SyntaxHighlighter/Scripts/clipboard.swf
- Add links in you blog template to link to the files uploaded in the above step. For this add the following code snippet at the head of your template, just after the <head> tag:
<link href='http://highlighter.abhi.sanoujam.googlepages.com/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shCore.js'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shBrushJava.js'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shBrushJScript.js'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shBrushXml.js'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shBrushProperties.js'/>
<script language='javascript' src='http://highlighter.abhi.sanoujam.googlepages.com/shBrushBash.js'/>
<style type='text/css'>
.console {
background-color: black;
color: #ffffff;
font-family: courier;
}
</style>
Now, replace http://highlighter.abhi.sanoujam.googlepages.com with your own url where you have uploaded your files.
Again notice that shBrushProperties.js and shBrushBash.js are actually not present in the syntax-highlighter that you downloaded. We'll create them in this post :)
Also we'll talk later about the .console CSS later. - Activate (call the js function) the highlighter. You can do this by adding the following code snippet at the end of your template just before the </body>tag:
<pre name="code" class="java">
public class HelloBlogger {
public static void main(String [] args) {
System.out.println("Hello Blogger!!");
}
}
</pre>
will look like:
public class HelloBlogger {I personally prefer using the <pre> tag for java and <textarea> tag for posting xml/html codes which normally contains characters like <, >
public static void main(String [] args) {
System.out.println("Hello Blogger!!");
}
}
Now here is shBrushProperties.js
I just created this brush so that my source for properties file can look nice.
Same for my bash scripts, which is shBrushBash.js:
You can see that there are only a handful of keywords for the Bash script brush right now. I intend to expand as my blogs keep rolling. For starters, its kinda ok.
Now coming to the console CSS style, this is just a small hack for displaying command lines to get a feeling of console/terminals
You can use this like;
<pre class="console">
$ javac HelloBlogger.java
$ java HelloBlogger
Hello Blogger!!
</pre>
Which will look something like:
You don't need to specify the name attibute :)
$ javac HelloBlogger.java
$ java HelloBlogger
Hello Blogger!!
And ohh, forgot to mention and found out again when clicking "Publish Post", if you are posting XML/HTML, anything which has < or >, replace them with < and > am thinking of putting up a post that will specifically do that.
Enjoy...