How to highlight source code in HTML?

Issue

I want to highlight C/C++/Java/C# etc source codes in my website.

How can I do this?

Is it a CPU intensive job to highlight the source code?

Solution

You can either do this server-side or client-side. It’s not very processor intensive, but if you do it client side (using Javascript) there will be a noticeable lag. Most client side solutions revolve around Google Code’s syntax highlighting engine. This seems to be the most popular one: SyntaxHighlighter

Server-side solutions tend to be more flexible, especially in the way of defining new languages and configuring how they are highlighted (e.g. colors used). I use GeSHi, which is a PHP solution with a moderately nice plugin for WordPress. There are also a few libraries built for Java, and even some that are based upon VIM (usually requiring a Perl module to be installed from CPAN).

In short: you have quite a few options, what are your criteria? It’s hard to make a solid recommendation without knowing your requirements.

Answered By – Daniel Spiewak

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.