Skip navigation.

Receive Post Comments Via EmailAll recent postsEdit Style Sheets Outside of Visual Studio.NET

Announcing Lightweight Source Code Highlighter

The long-promised code highlighter is now available for download. This is the same code that is behind my freefee online highlighter and source code viewer (example). In the code bundle you will also find two sample pages—stripped of all fanciness—which demonstrate how to use the highlighter (see the Driver folder).

For those of you who just tuned in: the highlighter adds the smallest amount of overhead markup. It runs in two steps: first it parses source code and does its magic, and then goes back and looks for chunks of coloring markup to optimize.

All along the hardest language to color was CSS with it numerous hacks (ironic, eh?) It seems it’s nearly impossible to write regular expressions to cover every imaginable CSS hack.

I hate the <font> element vehemently, so not having it allows to keep code free of fluff. Styling of processed code is done via CSS. Feel free to adjust colors to your liking.

If you really dig into the source code you’ll notice I could’ve picked collections better. I’ve written quite a bit about my frustration with collections classes in .NET (see .NET Collection Madness part 1 and part 2) so I won’t repeat myself here. I don’t think it’s worth spending any more time tweaking collections.

You will notice I resorted to a hack with line numbers. I chose to wrap them in a presentational element, <b>. I did this on purpose. I wanted line numbers to serve more of a presentational function, and in this sense the <b> element is only a presentational hook—nothing more! Turn off CSS and you’ll see—line numbers still stand out. It’s an acceptable hack which also helps keep the overhead at bay.

Comments

Comment permalink 1 David O'Hara |
Thanks for the great tool - I use php for my personal site but we use ASP.NET at work so I'll be integrating this with our internal developer site. BTW, I believe that you have a typo in the second sentance of the first paragraph - it's a "free" online highlighter - not a "fee" one. Amazing how much difference a single letter can make eh? ;)
Comment permalink 2 Milan Negovan |
LOL! Thank you for pointing it out! Yes, it does make a big difference. Damn late night coding. :)
Comment permalink 3 Pankaj |
Hi,

How to integrate CodeHighlighter.net with FreetextBox? Is there any sample example for reference?

Regards

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

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):