Read time: 1 minute

Syntax Highlighting

You know, I’ve always loved those tiny editor-like widgets in blogs/sites when you are looking for some code inspiration on the web.

I’ve realized that we had to bring this funny stuff is want to have a fancy tech Blog, so I was doing some homework…

…and voila!

def some_cool_python_function(cool_arg):
    '''Very relevant docstring
    for element in cool_arg:
         something = important_stuff(element) + 2
    return something

Now, how it’s done. After little research I’ve found Alex Gorbatchev’s SyntaxHighlighter. It’s very straight forward to install and very easy to use. You can find it here.

You just have to add the js scripts to your page as stated in the instructions, and will instantly have 30 different types of highlighters, including Python, Javascript and HTML.

A little thing that is not covered under instructions is that you have add support for XRegExp, you can download it here and after that simply load it in your section:

<script type="text/javascript" src="<path to javascript's>

Out of the box, the highlighter renders code on plain white background. We’ve made a little tunning to use a light grey on even code lines. You just have to edit shThemeDefault.css and modify line 24 like this:

.syntaxhighlighter .line.alt2 {
  background-color: #F2F2F2 !important;

Congrats Alex for your highlighter, it’s awesome!

Like what you read?

Subscribe to our newsletter and get updates on Deep Learning, NLP, Computer Vision & Python.

No spam, ever. We'll never share your email address and you can opt out at any time.
Comments powered by Disqus