Sunday, 4 September 2011

Code syntax highlighting on blogger

This is just a short post to test syntax highlighting for Blogger.

When looking for a better way to show code in my upcoming blogs, I came across this javascript syntax highlighter. I have it set up to only work with Python at the moment. It can be used by wrapping the code in the pre-tag:

<pre class="brush: python"> CODE GOES HERE </pre>

def co_sort(a,b):
	'''Sorts 2 lists according to the items in one.'''
	# r is needed so it works with arrays in b
	r = range(len(a))
	c = zip(a,r,b)
	c.sort()
	c = unzip(c)
	return c[0],c[2]

It seems to need some time to load, but overall it works pretty well. Apparently, there is a problem when using the greater-than and smaller-than signs, have to be escaped as &lt; and &gt; isntead.

See here how to set it up for your blog.

No comments:

Post a Comment