HaskellWiki:Syntax highlighting
From HaskellWiki
(→Styles) |
|||
| Line 21: | Line 21: | ||
putStr ("And the answer is: " ++(show (fst a))++"\n") | putStr ("And the answer is: " ++(show (fst a))++"\n") | ||
</haskell> | </haskell> | ||
| + | |||
| + | : Question: Would it be possible to have an markup tag, say <code><haskell-pretty></code> which would utilize the <code><math></code> environment to produce neat looking things like <math>\operatorname{foo} :: \forall \alpha \beta . \alpha \rightarrow \beta</math>, corresponding to <hask>foo :: forall a b. a -> b</hask>. | ||
== Inline formatting with <code><hask></code> == | == Inline formatting with <code><hask></code> == | ||
Revision as of 23:21, 13 March 2006
Syntax highlighting works for a bunch of languages including Haskell, using GeSHi and Jason Dagit's Haskell file, somewhat modified.
Contents |
1 Block formatting with <haskell>
To highlight syntax of a block of Haskell, enclose it in <haskell>...</haskell>. This uses the <pre> element. For instance:
{- My program -} import Prelude foo :: (Monad m) -> m (Int,Int) foo = (x-2,x - 1) where x = 3 -- The main function main :: IO () main = do a <- foo putStr ("And the answer is: " ++(show (fst a))++"\n")
- Question: Would it be possible to have an markup tag, say
<haskell-pretty>which would utilize the<math>environment to produce neat looking things like
, corresponding to .foo :: forall a b. a -> b
2 Inline formatting with <hask>
To highlight syntax of inline Haskell snippets, enclose the span in <hask>...</hask>. This uses the <code> element, which is inline. For instance: Inline highlighting is a bit of a hack at the moment, and may be buggy.
3 Styles
For Haskell (only) I have deliberately removed all formatting apart from foreground colour, and those I have tried to keep dark so as not to be visually distracting.
This is what I am trying to achieve:
- comments: grey
- keywords (including symbols): blue
- value literals: dark green
- known value identifiers (including symbols): green
- known type identifiers: red
- known classes: purple
- known modules: brown
I may also indent the entire block, similar to <blockquote>.
—Ashley Y 07:46, 10 March 2006 (UTC)
4 Other languages
This works for certain other languages too. For lisp, for instance, use <pre-lisp>...</pre-lisp> to format a block of lisp, and <code-lisp>...</code-lisp> to format text inline. <haskell> the same as <pre-haskell> and <hask> the same as <code-haskell>.
