Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight source code in HTML? [closed]

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?

like image 331
Niyaz Avatar asked Sep 16 '08 07:09

Niyaz


People also ask

How do you highlight code in HTML?

HTML <mark> Tag The <mark> tag in HTML is used to define the marked text. It is used to highlight the part of the text in a paragraph. The <mark> tag is new in HTML 5.


1 Answers

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.

like image 148
Daniel Spiewak Avatar answered Sep 28 '22 01:09

Daniel Spiewak