Screw Editor CMS Experience Part 1: Tidy up your HTML afterwards

Before some people are going to scream… You guys are all right, this is a feature implemented by Sitecore, not developed! You can see it in the API-CHM:

It uses a dll called TidyDll.dll created from the 2002-06-02 source code of HTML Tidy; see for more details about HTML Tidy. Please read the HTML files distributed with this file which have more information about Tidy.cs and TidyDll.dll.

You can find HtmlTidy-class and a Tidy-class in the System.Web.Tidy-namespace. You can easily Tidy your input this way:

string dirtyString = “<a href=’http://dirty-url’><b>Say hi to the (Dirty) world</b></a>”;
string allowedTags = “|b|i|”;
string cleanString = Sitecore.Web.Tidy.HtmlTidy.TidyHtml(dirtyString, true, true, true, allowedTags);

The comments on the classes tells e that the editor also uses this class, altough I can’t imagine CuteEditor and FCKEditor(5.3) don’t have this functionality built-in.

I guess an editor won’t be happy with you, he has just spent one and a half hour on screwing your validated XHTML. If you really want to get him pissed, check if you are in preview-mode and only tidy the stuff when you are ina live-mode.