ASP.NET MVC "Tidy" Html on the fly

I am wondering if there is any tool for Tidy Html on the fly.

Currently, in my application, I use MasterPage, and then my views are loaded into the Masterpage. The problem is that <asp:content runat="server" ... /> always adds extra output spaces / lines to the HTML output.

What I really would like to do is clean it so that

 <title> This is my title </title> 

will look like

 <title>This is my title</title> 

Now I understand that I can go through and install

 <asp:content ID="Content1" runat="server" ContentPlaceHolderID="TitleContent">This is my title</asp:content> 

But it becomes a pain, because I often use Ctrl + k + d , which leads to unwanted reformatting.

Also, when I use inline code like

  <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">User <%: Model.UserName%> - Urban Now</asp:Content> 

and use the "reformatting" keystrokes, then there are also line breaks before and after <%: Model.UserName%> , and there is no way to set this formatting to "Tools / Options / Formatting โ†’ Specific tag parameters" (at least not that that I can find).

+4
source share
1 answer

TidyManaged is a .NET / Mono managed shell for the open source, cross-platform Tidy library, HTML / XHTML / XML markup parser, and clean, originally created by Dave Raggett.

Usage example

 using System; using TidyManaged; public class Test { public static void Main(string[] args) { using (Document doc = Document.FromString("<hTml><title>test</tootle><body>asd</body>")) { doc.ShowWarnings = false; doc.Quiet = true; doc.OutputXhtml = true; doc.CleanAndRepair(); string parsed = doc.Save(); Console.WriteLine(parsed); } } } 

leads to:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content= "HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" /> <title>test</title> </head> <body> asd </body> </html> 

Note that <title>test</tootle> changes to the correct <title>test</title> .

https://github.com/markbeaton/TidyManaged

+1
source

All Articles