This project is read-only.

show HTML in description

Aug 31, 2009 at 7:00 PM

When I select "Only show description of posts" in the settings, the blog entries on my home page do not display HTML. These are posts that have nothing in the description box, so a truncated version of the body is used. What do I need to change so that the HTML will display?

Aug 31, 2009 at 7:53 PM

After looking into this further, I understand now that the reason the HTML gets stripped out when truncating is because you don't want to be left with unclosed tags. Also, if you want to truncate to a certain number of characters exactly, this would be a lot harder to do if you wanted to keep the HTML markup.

However, I do have a partial solution I'd like to share. In the blog I'm working on, I set the character limit to 1500, but I have a lot of short posts that were less than 1500 characters. These short posts were being stripped of their HTML even though there was no need to do so. Because the short posts aren't truncated, there is no "more" link, so viewers would never get to see the marked up version of the post. This code change will show HTML in the posts that are shorter than the character limit:

For the workaround, you have to download the source. In Web/Controls/PostViewBase.cs, starting at line 178 change

body = Utils.StripHtml(Post.Content);
if (body.Length > BlogSettings.Instance.DescriptionCharacters)
	body = body.Substring(0, BlogSettings.Instance.DescriptionCharacters) + "..." + link;
To this:
if (Utils.StripHtml(Post.Content).Length > BlogSettings.Instance.DescriptionCharacters)
	body = Utils.StripHtml(Post.Content).Substring(0, BlogSettings.Instance.DescriptionCharacters) + "..." + link;