Sunday, April 7, 2013

Quick Tip: How to show source code in the blog

I have been trying different solutions for showing source code in my blog.  This has been a little harder by the fact I'm trying to show Objective-C.  I have finally found just the trick. It's http://hilite.me/ by Alexander Kojevnikov.  It has a very simple copy/paste interface that just works.  You can also do some customizations and pick between may different styles.

Using it is as simple as:
  1. Paste your source code
  2. Hit Highlight
  3. Copy and paste the HTML


You can also customize the embedded css style information and pick the language.  I added a font size style to the css "font-size:small;" and here is what it looks like:

- (void)alertViewCancel:(UIAlertView *)alertView
{
    if( m_alertBlock != nil )
    {        
        m_alertBlock( kAlertViewCanceled );
        m_alertBlock = nil;        
    }    
}

The nice thing about this solution is that everything needed is embedded in the HTML block so there is no setup required on the blog itself.

Please feel free to follow me on twitter at @fivelakesstudio. I would love to hear if this was useful and what you do to show source code on the web.

Thanks for reading and be sure to visit us at Five Lakes Studio.

1 comment: