Using Highlight.js in Blogger

First posted on 12/01/2014

Applying highlight.js is pretty simple in Blogger. Here is a simple guide on how to install it.

  1. Go to your Blogger "Template" settings
  2. Go to "Edit HTML"
  3. Add the following line below <head> tag:
<link href='https://googledrive.com/host/0B1jxQOYRX3Mfc0FqcDJhNm14djg' rel='stylesheet'/>
<script src='https://googledrive.com/host/0B1jxQOYRX3MfU1plb0wyRWh6aEU'>
</script>
<script>
hljs.initHighlightingOnLoad();
</script>
  1. Use Highlightjs by wrapping your code in <pre><code>YOUR CODE</code></pre> like so,
<pre ><code >
@requires_authorization
def somefunc(param1='', param2=0):
    r'''A docstring'''
    if param1 > param2: # interesting
        print 'Gre\'ater'
    return (param2 - param1 + 1 + 0b10l) or None

class SomeClass:
    pass

>>> message = '''interpreter
... prompt'''
</code></pre>

Make sure to escape your code first using HTML Entities Encoder.
I've hosted the themes in my Google Drive. Read this tutorial for more information on how to use the hosted themes.

Show Comments

Get the latest posts delivered right to your inbox.