Sign in
  • Blog
  • Archive
  • About
  • Contact

Welcome to rickardnilsson.net

 

rickardnilsson.net is a weblog and the online home of web developer and father of three, Rickard Nilsson... More

Rickard blogs about creating software solutions using ASP.NET and agile practices.

Sites I've visited recently

Rtur.net / ASP.NET Forums / Karstad .NET User Group / JetBrains ReSharper / Scott Hanselman / dnrTV! / MSDN Radio / MIX'08 | Sessions / BlogEngine.Net / YUI Theater

Categories

  • RSS feed for .NET.NET
  • RSS feed for ASP.NET 2.0ASP.NET 2.0
  • RSS feed for BlogEngine.NETBlogEngine.NET
  • RSS feed for C# 2.0C# 2.0
  • RSS feed for C# 3.0C# 3.0
  • RSS feed for CSSCSS
  • RSS feed for Design by ContractDesign by Contract
  • RSS feed for Design PatternsDesign Patterns
  • RSS feed for JavaScriptJavaScript
  • RSS feed for TDDTDD
  • RSS feed for User tipUser tip

Five most recent posts

  • ReSharper User tip #2: Refactor rename namespace
  • Building a Photo Album widget for BlogEngine.NET
  • Applying stylesheets dynamically with jQuery
  • ReSharper User tip: Refactor magical strings to variable
  • Blogging with MS Word 2007

Tag cloud

  • ajax
  • blog
  • blogengine.net
  • c#
  • css
  • dbc
  • design by contract
  • dom
  • douglas crockford
  • foto
  • getweekofyear
  • gregoriancalendar
  • highlight
  • html
  • humble dialog box
  • iso 8601
  • javascript
  • jquery
  • jscript
  • julian bucknall
  • metaweblog api
  • model-view-presenter
  • mvp
  • photo album
  • picasa
  • recent posts
  • refactor
  • refactoring
  • release
  • resharper
  • rhino mocks
  • syntax
  • syntax highlighter
  • tdd
  • test coverage
  • types
  • web service
  • week
  • widget
  • word 2007
  • yahoo
  • yui

Recent comments

  • Building a Photo Album widget for BlogEngine.NET (3)
    Rickard wrote: Well, you can't at this point. My main goal with t… [More]
  • Building a Photo Album widget for BlogEngine.NET (3)
    nemesis wrote: excellent... but, how can I use it outside the … [More]
  • Building a Photo Album widget for BlogEngine.NET (3)
    Rickard wrote: Feel free to leave a comment if you have any feedb… [More]
  • Syntax highlighting in BlogEngine.NET (8)
    Rickard wrote: A release note has been posted here: http://www.ri… [More]
  • Syntax highlighting in BlogEngine.NET (8)
    Paul Podlipensky wrote: Please notify me too. ;) [More]
<< Week and strong contracts in Design by Contact | Syntax Highlighter Release 0.2 Beta >>

Syntax highlighting in BlogEngine.NET

Saturday, 12 April 2008 00:22 by Rickard

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>();
Stack<Name.Space.Customer> stack = new Stack<Name.Space.Customer>();
stack.Put(customer);
customer.Age = 24;

[Serializable]
public class Customer : ICustomer , IComparable<ICustomer> {
    public Customer(string name) {
        this.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 dotnetblogengine.net
    • does not support types in C#

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   syntax, highlight, c#, blogengine.net
Categories:   ASP.NET 2.0 | BlogEngine.NET | C# 2.0 | CSS
Actions:   E-mail | Permalink | Kick it! | DZone it! | del.icio.us | Comments (8) | Comment RSSRSS comment feed

Related posts

Syntax Highlighter Release 0.2 Beta Thanks to a great deal of interest on my post on syntax highlighting in BlogEngine.NET a while ago...Problem with Related Posts in BlogEngine.NET 1.4 With the new release of BlogEngine.NET a new feature was added that shows the description or part ...Building a Photo Album widget for BlogEngine.NETTutorial on how to implement the first steps of a Photo Album Widget for BlogEngine.NET

Comments

April 14. 2008 08:28

Kindler Chase

Please do notify me when you release the updated version.

Cheers!
::k::

Kindler Chase

April 14. 2008 21:23

Josh Collins

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

Josh Collins

April 19. 2008 06:51

stan

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

stan

April 19. 2008 06:52

trackback

Trackback from DotNetKicks.com

Syntax highlighting in BlogEngine.NET

DotNetKicks.com

April 19. 2008 18:47

Ira

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.

Ira

April 30. 2008 10:54

Jesper Lund Stocholm

Please let me know as well.

My particular problem is with syntax highlighting XML-markup.

Smile

Jesper Lund Stocholm

June 12. 2008 18:12

Paul Podlipensky

Please notify me too. ;)

Paul Podlipensky

June 25. 2008 09:46

Rickard

A release note has been posted here: www.rickardnilsson.net/.../...Release-02-Beta.aspx

Rickard

Saving the comment

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



 
Copyright © 2008 rickardnilsson.net