2005-12-08

 

Colourising code

If anyone is interesting in colourising Haskell code to paste into HTML on your blog (as in my previous entry below), it was done with a simple Haskell program (of course). HsColour is a little script I knocked up a few years back. It uses an intermediate mini-language of highlighting styles, and currently has two backends, one for HTML and another for ANSI terminal screen codes. I'm sure it would be simple to add other backend rendering formats - maybe CSS - with a tiny bit of effort. If you do modify it, or otherwise find it useful, please let me know.

The history of HsColour is vaguely interesting, because it was essentially a spin-off of my (winning) entry in the 0th International Obfuscated Haskell Contest - remorse. If you haven't seen remorse before, I'll try not to spoil the fun of discovering it, but suffice to say, it requires a mini-lexer for Haskell code, which I ripped out and re-used in HsColour. Don't worry - that isn't the obfuscated bit.

Comments:
It's not Windows compliant, since you hardcode /tmp into the program! Since Run.hs only works on Unix, and is only required for ANSI escape codes (which Windows doesn't have) commenting this bit out was sufficient to get it working. If you put up a darcs repo i'll send a patch :)

I was going to modify the documentation for Yhc to put up colourised sources, so I'll probably use this for that. I was hoping someone would have done something like http://lxr.mozilla.org/mozilla1.8/source/security/manager/ssl/src/nsCrypto.cpp for Haskell, ideally integrated with Haddock, but it seems no one has :(
 
btw, if its in darcs i'll also add a CSS mode, since outputting HTML with colour information is just wrong. It also allows you to drop the .hscolour when using CSS, and you can do more fancy feature - like graphics and watermarks if you wanted to.
 
A darcs repository is now available at
http://www.cs.york.ac.uk/fp/darcs/hscolour
 
However mean your gold in wow life is,buy wow gold meet it and live it ;wow gold cheap do not shun it and call it hard names.It is not so bad as you are.It looks poorest when you are richest.The fault-finder will find faults in paradise.wow gold kaufen love your life,poor as it is.maple meso You may perhaps have some pleasant,thrilling,maplestory power leveling glorious hourss,even in a poor-house.The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode;the snow melts before its door as early in the spring.sell wow gold I do not see but a quiet mind may live as contentedly there,cheap mesos and have as cheering thoughts,as in a palace.The town's poor seem to me often to live the most independent lives of any.May be they are simply great enough to billig wow gold receive without misgiving.Most think that they are above being supported by the town;powerlevel but it often happens that buy maplestory mesos they are not above supporting themselves by dishonest means.which should be more disreputable.Cultivate poverty like a garden herb,like sage.Do not trouble wow powerleveln yourself much to get new things,maple mesos whether clothes or friends
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?