If you want to insert code snippets with syntax-highlighting in your blogs on Blogger.com, then you can use google-code-prettify.
There are other syntax highlighting solutions out there, but this allows to do this very simply.
The steps are:
There are other syntax highlighting solutions out there, but this allows to do this very simply.
The steps are:
- Click on "Theme" (in LHS of blogger home page) or "Design" (in upper RHS corner).
- Click on "Edit HTML" button.
- Search for <head> tag in the html.
- Insert following line after meta tags in head tag:
<script src='https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=scala&lang=yaml&lang=bash&lang=xml&lang=sql&skin=sons-of-obsidian' type='text/javascript'></script>
For me it is just before <title> tag.
- Add onload property to <body> tag:
<body class='container' onload='prettyPrint()'>
- Here I have used "Sons-Of-Obsidian" style, you can use any of the available themes.
- Save the template.
- Now, in your Blog posts, whenever you want to insert code snippets, add the prettyprint class to your pre or code tags:
<pre class="prettyprint linenums"> var s:String = "Hello, World!"; </pre>
- This will be rendered in your blog post as:
var s:String = "Hello, World!";
Comments