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:
<p>With the new release of
<a href="http://www.dotnetblogengine.net">BlogEngine.NET</a> a new feature was added.</p>
Now, when the post is clipped it may end up cutting in the middle of the href:
<p>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.
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.
Download RelatedPosts.cs (3,8KB)