Dave's Free Press: Journal

violence, pornography, and rude words for the web generation

 

Recent posts

(subscribe)

Recently commented posts

(subscribe)

Journals what I read

geeky politics rant silly religion meta music perl weird drinking culture london language transport olympics hacking media maths sport web photography etiquette spam amazon film bastards books bryar holidays palm telecoms cars travel yapc bbc clothes rsnapshot phone whisky security home radio lolcats deafness environment curry art work privacy iphone linux unix go business engineering kindle gps economics latin anglo-saxon money bramble cars environment electronics
Sun, 16 Aug 2009

cgit syntax highlighting

NB: since writing this I have migrated all my code to Github and stopped using cgit. Therefore many of the links no longer work

For the last few months I've been using git for my version control system. It's better than CVS because it can handle offline commits. So if I'm using my laptop on a train, I can still use version control without having to have a notwork connection.

And to give a pretty web front-end to it for other people to read code without having to check it out of the repository, I use cgit, which I mostly chose because it's a dead simple CGI and not a huge fancy application.

One problem with cgit is that by default it doesn't do code highlighting. But it has the ability to run blobs of code through any filter you care to name before displaying them, so to get something nice like this all you need to do is write a highlighter and add a single line to your cgitrc:

source-filter=/web/www.cantrell.org.uk/cgit/highlighter

My highlighter program is this:

   1 #!/usr/local/bin/perl
2
3 use warnings;
4 use strict;
5
6 my $file = shift;
7
8 if($file =~ /\.(p[ml]|t)$/i) {
9 system "/usr/local/bin/perltidy -html -st -ntoc -npod -pre -nss -nnn"
10 } else {
11 system "cat -n";
12 }

Posted at 16:12 by David Cantrell
keywords: geeky | perl
Permalink | 0 Comments

Sorry, this post is too old for you to comment on it.

Archive