Haskell Syntax Highlighting and WordPress.com

While preparing my first post here I found that there was no default syntax highlighting for Haskell. Among several solutions suggested me by the web I’ve eventually chosen GNU Source-highlight coupled with sed. Here is an example of what you can get with it:

qsort :: (Ord a) => [a] -> [a]
qsort []     = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

After GNU Source-highlight is installed (usually from your linux distro’s repositories), you can run the following command from terminal to generate ready-to-publish html out of YourHaskellFile.hs:

source-highlight -i YourHaskellFile.hs | sed -e '1,/-->/d' -e 's/<pre>/<pre style="overflow: auto;">/'

This will print the output right into the terminal so you can copy-paste it into your blog.

This entry was posted in Haskell, Tips and tagged , . Bookmark the permalink.

2 Responses to Haskell Syntax Highlighting and WordPress.com

  1. Pingback: Problem 10 from Project Euler « Lazy Evaluations of Computing and Cycling

  2. Pingback: Puzzle: Network Theory, Petri Nets | My Math Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s