tags:

views:

61

answers:

3

Hi, i'm not sure to explain what i'm looking for.

What's the name of the "source code parser" for publish code, in HTML ? For example, when i write some source code here in stack overflow, system auto-detect the sintax and write "correct" source code in html.

I've noticed that exists the HTML <"code"> tag, but it simply write source code in "courier" font.

So i'm asking you if exists some "external" component that, given a text, parse it out correctly in a HTML page.

Thank you!

A: 

The system is called Markdown and here is an explanation of the code blocks it uses.

For the syntax highlighting that you mentioned, a different system is used called prettify.

Joe Philllips
Not really. I think the OP is looking for the syntax highlighting part, which is done by a different component IIRC.
Pekka
Sounded like he was looking for a few different things. Fixed
Joe Philllips
+3  A: 

SO uses prettify to syntax highlight the <code> snippets.

Source: Which tools and technologies were used to build the Trilogy?

It is a JavaScript tool that scans a page for code snippets, and colours them on the fly. The downside of this solution is that it doesn't work with JavaScript turned off. Seeing as syntax colouring is not really an essential task, it is arguably a small downside.

Pekka
Yes, thank you ! It is what i'm asking for !
stighy
Good link (the source)
Joe Philllips
A: 

There are two components to this:

  • The CSS/HTML structure for syntax highlighting (e.g. styles for printing keywords, #s, strings, comments etc... in certain colors). This can be generic or per-language.

  • The code parser (grammar parser), which breaks the code up into tokens and labels the tokens with the appropriate classes. This can be implemented on either back-end via whatever language your back-end is in; or on front-end via JavaScript (the example of the latter is Google's Code Pretty which is used by StackOverflow).

    It can be coupled with some heuristic logic to decide what language the code belongs to (and thus which grammar/parser to use).

DVK