Format Html Codeblocks like Stack Overflow

104 views Asked by At

Is there an open source project out there (written in Java Script or otherwise, for formatting code samples for well-known programming langauges?

I'm trying to create a documentation website that includes code samples. Here is an example of what my html looks like:

<pre><code>//example c#/html/etc code here</code></pre>

I'm using MarkDownSharp to format and encode the sample code, but Markdown doesn't handle the coloring. I notice when adding code samples to Stack Overflow, it automatically colors it in, making it much more readable.

Is this a proprietary technology that SO uses, or is that available somewhere?

3

There are 3 answers

2
Friedrich On

I think CodeMirror is the one you need.

jsfiddle is using this libary as well

0
xmojmr On

Igor Russkih (Cail Lomecb) created Colorer library, see http://colorer.sourceforge.net which has syntax highlighters for many programming languages and formats.

It is available as plugin into Far Manager or as standalone easy to use command line tool.

...running colorer -h -ei UTF-8 -eo UTF-16BE -o NAME.HTML yoursource.cpp will cause highlighted html generation of yoursource.cpp file with output name NAME.HTML, using UTF-8 as input encoding and UTF-16BE as encoding of result file...

Source: http://colorer.sourceforge.net/consoletools.html

0
Stephen Thomas On

For JavaScript (your expressed preference), the two most popular are Prism and highlight.js