[英]Visual Studio's Format Document – How to Write it in C#
I'm having a go at writing some C# code which overrides the Render method of the System.Web.UI.Page and then reformats the HTML before presenting it to the browser. 我正在写一些C#代码,该代码重写System.Web.UI.Page的Render方法,然后在将HTML呈现给浏览器之前重新格式化HTML。 This is purely experimental so overhead is not a concern right now.
这纯粹是实验性的,因此目前无需担心开销。
I'm perhaps a little learned in the ways of the regular expression and would like to utilise them here, but I can't seem to think of a real concise and elegant way of nicely formatting a HTML document. 我可能对正则表达式的方法有些了解,并且想在这里使用它们,但是我似乎无法想到一种很好的简洁而优雅的方式来格式化HTML文档。 I've managed to completely minify the HTML using regex, but as for correctly indenting it, I'm stumped.
我设法使用正则表达式完全缩小了HTML,但是为了正确缩进,我很困惑。
So, if you had a string of HTML, using C#, how would you reformat it in much the same way as Visual Studio's Format Document function does? 因此,如果您有使用C#编写的HTML字符串,您将如何以与Visual Studio的“格式文档”函数相同的方式重新格式化它? Any ideas would be greatly appreciated.
任何想法将不胜感激。
Use Tidy . 使用Tidy 。 I have used this .net wrapper quite successfully.
我已经非常成功地使用了.net包装器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.