To add code block and syntax highlighting, we need to use SyntaxHighlighter to help us. Luckily, blogger has include this integrated, what we need to do is add it to our template.
Go to Blogger Dashboard > Design > Edit HTML.
Search for code </head>
.
Copy following code on top of </head>
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <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/shThemeRDark.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/shBrushCpp.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.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/shBrushJScript.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.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/shBrushPerl.js' type ='text/javascript' /> <script src ='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type ='text/javascript' /> <script language ='javascript' > SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.config.clipboardSwf = ' http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf' ; SyntaxHighlighter.all();
Preview and save your template.
To make it work, in your post, do as follows:
1 2 3 4 5 <script class ="brush:cpp" type ="syntaxhighlighter" > <![CDATA[ Here is your code. ]]> </script >
or
1 2 3 <pre class ="brush:cpp" > Here is your code. </pre >
References:Adding a Syntax Highlighter to your Blogger blog SyntaxHighlighter