Saturday, May 30, 2015

How to Add Syntax Highlighting to Blogger

Code Prettify is an excellent Javascript-based syntax highlighter that supports many different languages and styles. To add it to Blogger, simply follow these two steps:


Step 1

Add the following before the </head> tag in your blog's template:
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

Step 2

To add "inline" code, enclose it with 
<code class="prettyprint"> 
  your code 
</code>

This looks something like this: <p> some html paragraph </p>

To add block code, enclose it with
<pre class="prettyprint"> 
  your code 
</pre>

This looks something like this:
<p> some html paragraph </p>

More Information

  • Much more information, e.g. to choose the language, change the style, ... etc.,  can be found at Code Prettify

No comments :

Post a Comment