Syntax highlighting in BlogEngine.NET

BlogEngine.NET ships with an extension that automatically highlights source code in blog posts. All that is required is that the source code block is surrounded with [code:lang][/code] tags. The extension will markup the code with CSS classes and the default theme includes a default color scheme for code elements like keywords, comments, and so forth. The extension ships with support for HTML, C#, JavaScript, T-SQL, MSH, and Visual Basic.

In forums and blogs in the BlogEngine community issues with the syntax highlighter extension has been brought up. Some of it can be found here, here, and here. Many has complained about how hard it is to use and lack of proper documentation. To get the tags to be recognized by the extension you have to format your post in a really precise manor with a leading and trailing <p>p>. Besides taking up a lot of unnecessary space when editing the post, this is why so many has complained that they can't get it to work. If the block is not correctly surrounded with the right amount of line breaks two things can happen. Either the whole code block is masked or the code is shown but the tags are rendered as part of the code block.

My own experience with this is pretty much the same and the only way to find out how it works was for me to read and step through the code. Since the extension is open source there is no hinder for improving the code base, hence I've been working to improve it to meet the community need, as well as my own. In addition to the mentioned usability issues I missed highlighting of types in C#, that is class, interface, and struct names which we are used to see in Visual Studio colored in cyan.

New version

I'm about to present a new version of the extension which will include the following improvements:

  • Highlighting of types in C#
  • The code block is recognized anywhere in the blog post and does not require any special formatting before or after the code tags.

    Leave a comment on this post if you wish to be notified when the new version is available.

    Example of syntax highlighting in BlogEngine.NET using the improved version

    ICustomer customer = new Customer("kalle");
    RegEx regex;
    ICollection<Customer> coll = new ICollection<Customer>();
    StackCustomer> stack = new StackCustomer>();
    customer.Age = 24;
    public class Customer : ICustomer, IComparable<ICustomer> {
        public Customer(string name) { 
   = name; 
            person = new Person(name); 
        public int Age {
            get { return age; }
            set { age = value; }
        IPerson _p = Person.CurrentUser;
        IPerson person;
        internal IPerson Person {
            get {
                return this.person;
        private ShopingCart cart = new ShopingCart();
        protected ShopingCart GetCart() { return cart; }

  • Related work
    • C# code format
      by Jean-Claude Manoli
      author of the syntax highlighter extension for BlogEngine.NET
      Not the same code as shiped with BlogEngine.NET
      does not support types in C# 
    • Syntax highlighter
      by Wilco Bauwer
      linked from the extensions list on
      does not support types in C#

    Comments (13) -

    • Kindler Chase

      2008-04-14 08:28:12 | Reply

      Please do notify me when you release the updated version.


    • Josh Collins

      2008-04-14 21:23:51 | Reply

      Yes, I definitely want to check out an updated version!

    • stan

      2008-04-19 06:51:22 | Reply

      Please notify me!  I had just given up on the highlighter, this is great!

    • Ira

      2008-04-19 18:47:08 | Reply

      I would love to see this happen. I have been wanting a syntax highlighter that could recognize types in C#. Please let me know when this happens.

    • Jesper Lund Stocholm

      2008-04-30 10:54:35 | Reply

      Please let me know as well.

      My particular problem is with syntax highlighting XML-markup.


    • Paul Podlipensky

      2008-06-12 18:12:59 | Reply

      Please notify me too. ;)

    • darren

      2008-11-20 15:27:33 | Reply

      thanks for this - got it up and running no problem in 1.4.5 Smile


      2009-05-15 18:29:03 | Reply

      im glad the highlighter errors dont happen anymore

    • IP PBX

      2009-05-15 18:29:43 | Reply

      or do they?

    • Sulumits retsambew

      2009-07-03 20:28:56 | Reply

      great coding.. thanks for sharing it.. keep it up man

    • what news today

      2009-07-11 11:33:31 | Reply

      great tutorial...looking for more post in your blog

    • Rickard

      2009-09-04 09:09:59 | Reply

      @Endowme no, its not a regular template. I've designed it my self.

    Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.