I wrote a little extension for BlogEngine.NET 1.2 that parses BBCode for use in the comments. BBCode allows you to write square bracket syntax to format your text. It’s smart because it gives more power to the people commenting and it gives you total control over the HTML output because BBCode is not HTML – the parsing takes place server side when the comment is served and not when it is saved.

So, when you write a comment you can now use these few BBCode tags. More will come when I find out which ones make most sense.

Bold
[b]some text[/b]

Italic
[i]some text[/i]

Cite
[cite]some text[/cite]

You can easily add new tags your self by adding a single line in the extension. Also, if you want to be able to write BBCode syntax in your posts, you can easily do that by adding a single line to the constructor of the extension. Just type in this line:

Post.Serving += new EventHandler<ServingEventArgs>(Post_CommentServing);

Safety first

A BBCode parser is not as straight forward to write as you might expect. It’s not just a matter of replacing [b] with <strong> since that can lead to trouble. Let’s say someone writes this comment:

It’s a [b]lovely weather today.

If we just replace [b] with <strong> then the entire page will become bold since the tag is never closed. That means a wrong formatted comment can turn your entire website into something very ugly.

Instead we need to make sure that all BBCode tags are closed before we parse them. This extension will parse all the correctly closed BBCode tags even though there is a malformed tag in the same comment. It simply ignores the malformed tag and moves on and thereby doesn’t screw with the design of the site.

Implementation

Download the BBCode.cs file below and paste it into the /App_Code/Extensions/ folder of your BlogEngine.NET 1.2 installation.

BBCode.zip (721 bytes)

Al Nyveldt did it again. I’m always amazed whenever he does a screencast. He’s just so relaxed and natural when he explains tech stuff and he does it with such a confidence. I wish I had that talent.

He just made two new screencast about setting up BlogEngine.NET 1.2 for the first time. The first one is about installing it using the default XML data provider and the second is a more detailed installation guide for setting up SQL Server as a provider. They are very short and to the point. I like that. It’s always a joy to listen to people like him. Go check it out.

The first video also explains how to adjust the robots.txt file so search engines can index all your pages and posts with ease. Since Microsoft Live Search, Yahoo and Ask started supporting Google’s sitemap format, it has become somewhat painless to let those search engines index your entire website. That’s why it is important to know about the XML sitemap feature of BlogEngine.NET. The versions earlier than 1.2 also has this feature by the way.

BlogEngine.NET 1.2 only support XML and SQL Sever 2000/2005/2008 but the next version will support all standard T-SQL databases like MySQL, PostgreSQL, Oracle etc. out of the box.