Sunday, June 6, 2010

How to Publish Source Code in Blogger

There are several ways to do the job. But probably the simplest one is described here. Many ways involve having another host server. The method suggested in the link is based on "Syntaxhighligher." Simply tweak the template HTML file as the following instructions:
  1. Go to Layout -> Edit HTML 
  2. Add the following lines right before </head>
    <link href='http://syntaxhighlighter.googlecode.com/svn/trunk/Styles/SyntaxHighlighter.css' rel='stylesheet' type='text/css'/> <script language='javascript' src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js'/> <script language='javascript' src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js'/>
     
  3. Add the following lines right before </body>
    <script language="javascript">

    dp.SyntaxHighlighter.BloggerMode();

    dp.SyntaxHighlighter.HighlightAll('code');

    </script>


  4. Save the template. Then you are done.


How to publish source code?
  1. Type your article as usual.
  2. Copy your code to here.
  3. Copy your encoded code from the link to where you edit your article.
  4. Enclose the code by
    <pre name="code" class="cpp">
    </pre>


  5. Then publish your post as usual.

No comments:

Post a Comment