Have a look at the Prettify JavaScript library. It's the one generally used by people (it's the one being used here on SO, for example.)
You would use it like this:
In your
element:In your
element:def say_hi():
print("Hello World!")
That's for simple use of the library. If you're using other JavaScript on your page I would recommend other methods for enabling the Prettify library (i.e., don't use the onload attribute of the
element.) For example, if you're using jQuery, I wrote this jQuery plugin that I usually use to syntax highlight certain elements:// Extend jQuery functionality to support prettify as a prettify() method.
jQuery.fn.prettify = function () { this.html(prettyPrintOne(this.html())); };
Used like this:
$('#my-code-element').prettify();