Python Syntax Highlighting for Blogger with highlight.js

In order to pass the coding interview questions I have to write some code and it would be a wonderful idea to post the code of python interview question to this blog. Unfortunately Blogger platform doesn’t have syntax highlighting feature by design.

I tried a number of excellent free Syntax Highlighters like Google Code Prettify a highlighter used on Stack Overflow and SyntaxHighlighter by Alex Gorbachev, but decided to go with Highlight.js. It is small, fast and rich.

There are straightforward instruction how to configure prebuilt version of highlight.js with 23 commonly used languages on Blogger platform using open source cdnjs CDN:

  • Take backup of your blogger template
  • Open your Blogger template in Edit HTML mode
  • Paste the following code before head tag
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/default.min.css">
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    
  • Save Blogger Template
  • Now you could simply enclose Python code in pre tags
Hello, World! Python style :
print("Hello, World!")

Now I am ready to python interview challenge.

No comments:

Post a Comment