• Blog
  • Archive
  • About
  • Contact
Sign in

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.

Top Posts

  • Applying stylesheets dynamically with jQuery
  • ASP.NET MVC 2 Framework and Unity 2.0 Dependency Injection Container
  • Code Kata Cast
  • Dependency injection in ASP.NET MVC with Unity IoC Container
  • Isolate your code from ASP.NET with Moles Isolation Framework

Sites I've visited recently

  • Ninetech - Affärsnytta med IT
  • JetBrains Team City
  • Vimeo

Categories

  • .NET
  • Agile
  • ASP.NET 2.0
  • ASP.NET 3.5
  • ASP.NET MVC
  • BlogEngine.NET
  • C# 2.0
  • C# 3.0
  • CSS
  • Design by Contract
  • Design Patterns
  • iPhone
  • JavaScript
  • Kata
  • Moles
  • TDD
  • Testing
  • Unit testing
  • Unity
  • User tip

Five most recent posts

  • Prime Factors Kata in C#
  • iPhone developer
  • ASP.NET MVC 2 Framework and Unity 2.0 Dependency Injection Container
  • Isolate your code from ASP.NET with Moles Isolation Framework
  • Moles Isolation Framework from Microsoft to be compared with TypeMock Isolator

Tag cloud

  • agile
  • ajax
  • asp.net
  • asp.net 3.5
  • asp.net mvc 2
  • bdd
  • blog
  • blogengine.net
  • c#
  • cocoa touch
  • code kata
  • correction
  • css
  • dbc
  • dependency injection
  • design by contract
  • dom
  • douglas crockford
  • fakes
  • foto
  • getweekofyear
  • gregoriancalendar
  • highlight
  • html
  • httpcontext
  • humble dialog box
  • inversion of control
  • ioc container
  • iphone
  • iphone os
  • iso 8601
  • isolation
  • isolation framework
  • javascript
  • jquery
  • jscript
  • julian bucknall
  • klarsynt
  • live template
  • metaweblog api
  • microsoft research
  • mocks
  • model-view-presenter
  • moles
  • mvp
  • ninetech
  • objective-c
  • patterns & practices
  • photo album
  • picasa
  • recent posts
  • refactor
  • refactoring
  • release
  • resharper
  • rhino mocks
  • roy osherove
  • stubs
  • syntax
  • syntax highlighter
  • tdd
  • tdd masterclass
  • test coverage
  • testing
  • typemock
  • types
  • unit test
  • unity
  • unity 2.0
  • update
  • web service
  • week
  • widget
  • word 2007
  • yahoo
  • yui

Blogging with MS Word 2007

Monday, 28 July 2008 19:13 by Rickard

Thanks to the new MetaWebLog API in BlogEngine.NET you can use MS Word 2007 to write your blog posts including using graphics, charts and the full feature set of Word 2007. Read about how you set it up at Rtur.net. You can even use Word 2007 to edit posts on the blog server.

Note: This post was published using Word 2007.

Tags:   blogengine.net, word 2007, metaweblog api
Categories:   BlogEngine.NET
Actions:  
Share | Comments (1) | |

Problem with Related Posts in BlogEngine.NET 1.4

Sunday, 27 July 2008 03:35 by Rickard

With the new release of BlogEngine.NET a new feature was added that shows the description or part of the post when listing related posts. If the description is empty a small part of the post content is listed instead and here in lies the problem. The post content is simply clipped as a certain length without regard to any tags in the post. Let's say a related posts goes like this:

With the new release of
<a href="http://www.dotnetblogengine.net">BlogEngine.NET</a> a new feature was added.

Now, when the post is clipped it may end up cutting in the middle of the href:

With the new release of <a href="http://www.dotnetblo...

And this may probably screw up the layout and content of the remainder of the page, besides producing an html that will not validate.

Solution

This issue has been discovered and fixed for a future release of BlogEngine.NET. However, if you, like me don't or can't wait that long here's a fix:

The problem is that the html tags are not closed so the simple solution is to strip the related post of all html. My first thought was to parse the post and close all open tags but when I thought about the actual intent of the related posts I realized that it is to provide a preview of the post content, not to show part of the actual post. So, by stripping all html tags all images and links are removed and only the text remains, which provides a really nice preview.

To implement the solution you only have to edit one line of code in the App_Code/Controls/RelatedPosts.cs file on row 139:

string content = post.Content;

 

string content = Utils.StripHtml(post.Content);

Or you can download the appended file and replace the one in the App_Code/Controls/ folder.


RelatedPosts.cs (3,77 kb)

 

Tags:   blogengine.net, recent posts
Categories:   BlogEngine.NET
Actions:  
Share | |

Syntax Highlighter Release 0.2 Beta

Monday, 5 May 2008 21:50 by Rickard

Thanks to a great deal of interest on my post on syntax highlighting in BlogEngine.NET a while ago I'm now releasing a new version. It is based on the version that ships with BlogEngine.NET but it has been augmented as well as refactored to support more language elements like types in C#. The code formatter has been extracted and the new version is released through CodePlex.

Additional features compared to version 0.1

  • Highlighting of types in C#
  • Architecture to support additional language elements

Syntax Highlighter Extension

  • The code block is recognized anywhere in the blog post and does not require any special formatting before or after the code tags
Download
  • www.codeplex.com/syntaxhighlighter

I will start a series of blog posts on using and developing the new version. I thank those who have shown interest.

Tags:   syntax highlighter, c#, types, blogengine.net, release
Categories:   BlogEngine.NET
Actions:  
Share | Comments (19) | |

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#

 

Tags:   syntax, highlight, c#, blogengine.net
Categories:   ASP.NET 2.0 | BlogEngine.NET | C# 2.0 | CSS
Actions:  
Share | Comments (17) | |
 
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© 2008-2010 rickardnilsson.net
Creative Commons-licens