One of the requirements of the blog was to be able to post highlighted code syntax particularly in python. For this I'm using SyntaxHighlighter 1.5.1 which is excellent for this purpose but true to the spirit of the blog needs a little tweaking especially to use with blogger.
- Download and unrar the code from the SyntaxHighlighter website
- To make the code xhtml compatible alter line 145 in shCore.js: change "if(tags[i].getAttribute('name')==name)" to "if(tags[i].getAttribute('title')==name)"
- The python highlighter doesn't work in safari so get my shBrushPython file and use that in place.
- Upload your files somewhere (I added mine to Google Pages as others have suggested - which I had to do in IE 7 as Safari doesn't show the upload function on Google Pages.
- Change your Blog template as described in this post.
- Use the newer Blogger in draft post editor to add your posts to avoid the annoying < br / > insertions by the default editor (at July 08). You should be able to add something like this to your posts!
<pre class="python" title="code">#A module
import something
</pre>
Which will give you hopefully highlighted code like this:
#A Module import something
Some other tests with the syntax highlighter. Its pretty basic but good enough for my purposes.
a_single_quoted_string = 'single'
a_double_quoted_string = "double"
triple_quoted = """ triple
across lines"""
def somefunction(some_arg=None):
pass
return
somefunction()
class someclass(object):
"""Code here"""
def __init__():
pass
0 comments:
Post a Comment