Highlighting Code – Any Code!

Ok, so any self respecting site developing applications for the desktop and the web needs to be able to display code clearly. This means formatting it so it is laid out in a similar style to the code editor it was created in. So, mono-spaced font type and code highlighting is essential to making your code readable to others. Of course this doesn’t simply mean covering HTML and CSS languages to code highlight, and be assured that will be posting code snippets in a whole range of programming and scripting languages!

With this in mind we have implemented a system to highlight code written in many different programming languages. See below for a couple of quick examples:

Here is some formatted C# code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication22
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            MessageBox.Show("Hello World!");

Below is some more formatted code. This time XAML (XAML, or Extensible Application Markup Language, is the new mark-up language used in Microsoft’s WPF language).

This time no line numbers this time, so this gives us flexible options for displaying formatted code:


If you notice from the above couple of examples the code fits in nicely so no scrollbars are needed. However, there will be lots of times when scrollbars ARE needed so every line of code is accessible. As anyone who has programmed know, code often covers multiple lines and so this feature is important.

See below for a HTML code snippet highlighted with line numbers (line numbers don’t have to begin at zero by the way, the example below starts at line number 10) including horizontal scrollbars for readability:

   New Document 


However, the fun doesn’t stop there! We can now show code highlighting for many more programming languages, including:

ActionScript, C++, C#, CSS, Fortran, Java, JavaScript, MySQL, PHP, Python, Rails, Ruby, Visual Basic, WPF, XAML, XML

So, this is something to keep us more than busy for a while!!

This entry was posted in Misc, PHP, Programming and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.