Search code examples
parsingprogramming-languagessyntax-highlightingmarkdown

Guessing a code block's language for correct syntax highlighting


I'm quite puzzled how the syntax highlighting feature here on SO works, but I have seen similar somewhere else. How does this work?

  • Is there one parser which can parse multiple languages at once?
  • Or, are several passes of different parsers needed and the best parsing result is used?
  • Or, is only a shallow analysis performed and the language is then guessed based on heuristics?

And if one of these is true, how does it work?


Solution

  • Check out Javascript code prettifier on Google Code.