7

Here is a sample Haskell code block:

 -- This is a comment <- notice how this is syntax highlighted as though it were code
 {- This is also a Haskell comment -}

 // This isn't even a comment in Haskell, it's a syntax error.
 # This isn't a comment either.
 -- // Only this is a comment to both Haskell and SO's syntax highlighter.

 -- Some actual Haskell code:
 f :: a -> a
 f x = x

 -- Some more actual Haskell code:
 f' :: (a -> a') -> [a -> a] -> a -> a'
 f' f0 fs = foldl' (.) f0 fs
7
  • 2
    Looks like you're doing much better than VB - ' really messes the formatting: meta.stackexchange.com/q/6812/7586 . Anyway, assuming there's no AI code that can detect the language, what are you suggesting? -- is also an SQL comment, but it can be tricky separating it from the decrement operator.
    – Kobi
    Oct 24, 2010 at 11:17
  • Maby read in two words. And if second word is alphanumeric, parse it as haskell? Oct 24, 2010 at 11:31
  • @Kobi: No actually it's worse. ' in Haskell is a character that can present in an identifier, so we can't use the "close the comment" trick in VB.
    – kennytm
    Oct 24, 2010 at 13:54
  • is the space after the double hyphens required? Would sure make things easier
    – Brad Mace
    Oct 24, 2010 at 14:55
  • According to Jeff, Haskell (lang-hs) is now explicitly supported.
    – Pops
    Sep 25, 2012 at 6:33
  • 1
    By the way, is lang-hs it the same as lang-haskell? Also, haskell seems to produce different results than lang-haskell—what's with that? Mar 1, 2014 at 20:01
  • @ErikAllik See my question
    – crockeea
    Mar 8, 2014 at 5:40

2 Answers 2

2

The questions are all tagged with the language, right? So they could use the tags to determine which highlighting quirks to enable.

3
  • This won't work. Say if a post is tagged [python] and [haskell] for comparing / translating some language constructs, what language should the code apply? Or if the question is [language-agnostic]?
    – kennytm
    Oct 24, 2010 at 16:05
  • If it's language agnostic they can just do what they do now. If it's got multiple language tags, maybe then it should also just do what it does now. But if it's got one language tag I don't think it would hurt to improve the highlighting a little.
    – Brad Mace
    Oct 24, 2010 at 16:23
  • @KennyTM I think that's a relatively rare edge case, and as bemace points out, it wouldn't hurt if implemented reasonably. Apr 30, 2011 at 8:21
1

There is no consistent syntax highlighting on StackOverflow. While prettify.js, the syntax highlighting mechanism it uses, does support a lot of languages, there is currently no way for an author to get the language tag through to that script. Haskell is only one of many languages that suffer from this. In guess-mode, prettify.js seems to lean strongly towards languages with syntax similar to C.

It seems that something like <code class="prettyprint lang-haskell"> could be put on the HTML whitelist for Markdown, but this proposal has gone unanswered for over a year now. See for example this question: Syntax highlighting language hints.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .