In this and in my other Blogspot blog I use SHJS to highlight syntax in Haskell snippets. SHJS is a JavaScript highlighter which uses language definitions from GNU Source-highlight.
To use it, you need to put online:
- SHJS main script: sh_main.min.js,
- One or more language definitions files. Haskell one: sh_haskell.min.js,
- One of the stylesheets. (You can preview them on the main SHJS page)
You may wish to download more than one language definition and concatenate all JavaScript files together. It's OK
Then put this somewhere in the <head>
:
<head> ... <script type="text/javascript" src="http://example.com/path/to/sh_main.min.js"></script> <script type="text/javascript" src="http://example.com/path/to/sh_haskell.min.js"></script> <link type="text/css" rel="stylesheet" href="http://example.com/path/to/stylesheet.css"> ... </head>
And add a callback to documents' body
element:
<body onload="sh_highlightDocument();">
Finally, wrap your Haskell snippets with <pre class="sh_haskell"></pre>
. This is how it looks:
-- Fibonacci numbers fibs :: [Int] fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
As far as I know, Haskell language definition has already found its way to GNU Source-highlight, but the corresponding file is not yet shipped with SHJS. So you can download it either from my source repository, or generate from the language definition file (haskell.lang
) yourself.
Haskell is a quirky language to highlight, but this language definition handles it reasonably well, better than the current google-code-prettify, and much better than the current GeSHi highlighter.
Update, 2011-01-25: Suprisingly, this highlighter is still better than more recent highlight.js and an alternative language definition for SHJS by Nicolas Wu (zenzike).
So this is the complete list of JavaScript highlighters for Haskell which I know about:
- this highlighter (SHJS + Haskell language definition) (test screenshot)
- highlight.js (Haskell is supported since January 2010) (test screenshot)
- google-code-prettify (test screenshot)
- GeSHi (test screenshot)
- An alternative Haskell language definition for SHJS by Nicolas Wu (test screenshot)