Wednesday 21 March 2007

Syntax Highlighting in blogger

Eventually (in the far distint future) I want to set up my own server to host rails apps on and perhaps a blog driven by Mephisto - particularly cause you can get good syntax highlighting plugins for it.

In the meantime, I discovered that you can export your current highlighting theme from textmate as CSS, using the bundle command 'Create CSS From Current Theme' (vaguely enough ;) ). Then any time I want to post code snippets here, I use the similarly vague command 'Create HTML From Document'

All you need to do is copy and paste the CSS into your Blogger template.

Beautiful.

3 comments:

Yi Wen said...

Could you post your css here? Since I don't have textmate around, thanks.

Barry said...

Yi Wen,

Apologies for the delay in replying. Unfortunately the css wont be of any use to you without textmate.

For example - if I want to pretty print:

def test
   foo
end


Textmate just wraps each word in a html span. One class for a keyword, one class for a variable, etc...

<pre class="textmate-source"><span class="source source_ruby source_ruby_rails"><span class="meta ...
foo
<span class="keyword keyword_control keyword_control_ruby">end</span></span></pre>


My corresponding css file just defines the colour of each class.

I'm not sure, but other editors may give you the same html/css 'pair'. Feel free to mail me and I'll try to be of more help.

Ivar Refsdal said...

I made something similar if you're interested:
Check it out here:
http://heim.ifi.uio.no/~ivarref/blogger/hoho.html

Check out the source for the file. You can have one line code snippets with syntax highlighting and some other features.