Is there a tool/library/function in C# which tabifies or indents generated html code without validating or tidying the input?
Edit:
Indent generated HTML code from JavaScript TextEditors, including but not limited to TinyMCE. No HtmlTextWriter. Must not expect a valid XML/XHTML/HTML code.
Requirement:
- Add a new line before and after opening and closing tags.
- Indent content inside tags (Tab or 4 Spaces).
- Split a long line (having N number of words) into multiple indented lines.
- Do not change the input even though it is not a valid HTML. Only tabify/indent and split long lines.
Upto this point, I have:
private string FormatHtml(string input)
{
//Opening tags
Regex r = new Regex("<([a-z]+) *[^/]*?>");
string retVal = string.Empty;
retVal = r.Replace(input, string.Format("$&{0}\t", Environment.NewLine));
//Closing tags
r = new Regex("</[^>]*>");
retVal = r.Replace(retVal, string.Format("{0}$&{0}", Environment.NewLine));
//Self closing tags
r = new Regex("<[^>/]*/>");
retVal = r.Replace(retVal, string.Format("$&{0}", Environment.NewLine));
return retVal;
}