markdown in BlogEngine.NET

BlogEngine.NET has half baked support for markdown. You can install MarkdownFormatterExtension but this doesn’t do anything unless you enter raw text into the HTML editor view.

There is an additional problem that the posts are saved as Xml and as such all the white space is removed during the save process.

You can get around this by tweaking the Post class as follows:

/// <summary>
///     Gets or sets the Content or the post.
/// </summary>
public string Content
{
    get
    {
        string content = this.content;
        if (content.StartsWith("<![CDATA[") &&
            content.EndsWith("]]>"))
        {
            content = content.Substring(9, content.Length - 12);
        }
        return content;
    }

    set
    {
        string content = value;
        if (!content.StartsWith("<![CDATA[") &&
            !content.EndsWith("]]>"))
        {
            content = string.Format("<![CDATA[{0}]]>", value);
        }
        base.SetValue("Content",
            content, 
            ref this.content);
    }
}