26 August 2014

Enabling code syntax highlighting for my blog

Since I'm planning to write lots of posts about development and configuration, I needed a nice code highlighting feature for my blog. It looks like that blogger.com does not provide any code highlightings by its own, so I searched google and found the following solution to work quite well.

Template Preparation


1. Open your template in HTML edit mode
2. Copy the following code to your html header section:

 <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
 <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>

 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>  
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js' type='text/javascript'/>  
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>  
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>  
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> 

3.Copy the following code to your html body section just before you </body> end tag:

<script language='javascript'>
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
</script>

Adding a code blog inside a posting

Now you can insert code to your blog post like the following:

<pre class="brush: java">
    private static boolean unrestrictedPoliciesInstalled = 
            SecurityTestUtil.checkUnrestrictedPoliciesInstalled();
    
    final TestParam test;
    
    public KerberosTokenTest(TestParam type) {
        this.test = type;
    }
</pre>

The result will look like this:

    private static boolean unrestrictedPoliciesInstalled = 
            SecurityTestUtil.checkUnrestrictedPoliciesInstalled();
    
    final TestParam test;
    
    public KerberosTokenTest(TestParam type) {
        this.test = type;
    }

Links


Since is the content from http://alexgorbatchev.com/ is sometimes very slow or not available at all, this really slows down your own blog page. Therefore I found the following solution to work much better by using google drive to store your css & js files:
http://www.komku.org/2013/08/how-to-host-javascript-or-css-files-on-google-drive.html

Since Google blocks direct access to shared files. This tip is not working any longer. I had to use my own webserver for this.

9 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. I have tried using it Java... but it didn't work.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head.
    I am highly impressed with your blog. It is very nicely explained.
    Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    ReplyDelete
  5. Great post.I am really appreciate for this.I am highly impressed with your blog. It is very nicely explained. Have a look on yii2 development company,

    ReplyDelete
  6. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    rpa training in bangalore
    best rpa training in bangalore
    RPA training in bangalore
    rpa course in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  7. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore | Best AWS Amazon Web Services…
    Amazon Web Services (AWS) Training in Pune India
    AWS Training | AWS Training and Certification | AWS online training
    AWS Training in Bangalore cost| Aws training in Bangalore with placements

    ReplyDelete
  8. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    AWS Training in pune
    AWS Online Training

    ReplyDelete