Skip navigation.

Code-Behind For HTTP HandlersAll recent postsDOCTYPE In FrontPage?

Code Highlighter Is Now In Beta

My set of online tools has gained an addition—a code highlighter. I've looked around for a decent code highlighter for quite some time now, but each and every one I found produced a tag galore a-la 1997, i.e. with inline font and color tags, etc. Needless to say this code doesn't validate as anything and it bloats your pages beyond belief. Therefore I set out to write one of my own.

Right from the start I set a couple of goals:

  1. Add minimum overhead markup to the original source code.
  2. Make code coloring easy to configure.
  3. Produce code that validates against XHTML Strict. If you're not after the Standards mode, don't worry—it doesn't affect you. Consider this a free add-on.

I am a big believer in separation of content and presentation. Hence the colored code itself contains only wrapping elements (mostly <span>) with appropriate class attributes. Coloring is configured through an external stylesheet. To use the colored code in your app simply copy what's in between <pre class='coloredcode'>...</pre> tags and link to the stylesheet, colorcode.css.

A quick comparison (not to point fingers at anyone). A brand new web form with minor changes (such as words in the comments that resemble reserved keywords to confuse some highlighters) weighted

  • 6.8K at Aylar
  • 12.4K at squishyWare and
  • humble 2.9K + 339 bytes of CSS on this site. That's 53% and 74% less code respectively.

I plan on optimizing the algorithm even more, e.g. two or three keywords in a row can be colored as one keyword.

The tool allows you to preview the colored code and download it along with its stylesheet to your computer.

At this time my code highlighter supports C#, VB.NET and XML. HTML/ASPX and CSS are on my list next. I encourage participation in testing the service. Once the code is stable I want to make its source and binaries available to everyone.

Let the coloring commence!

Comments

No comments yet

Emails and Notifications

Would you like to be notified when somebody responds to this post? 

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):