寻找一个离线库来格式化HTML,我可以使用.NET代码 [英] Looking for an offline library to format HTML that I can use with .NET code

查看:192
本文介绍了寻找一个离线库来格式化HTML,我可以使用.NET代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须处理密集格式化的HTML中的问题,这种问题实际上是无法读取的,所以我想要一个库漂亮打印,格式化,美化,或者在管理这个HTML的.NET应用程序中调用它。

目前,我将其复制并粘贴到Visual Studio 2012中,并将其格式化,然后将其粘贴回应用程序,但这有点乏味。



如果在解决问题的时候能够有效地逆转这个过程并去掉所有的空白区域,那也是很方便的。

顺便说一句,我知道改变HTML的格式有时会导致意想不到的结果(我正在看你的IE),但我可以忍受。


<解决方案



从项目页面:

TidyManaged



这是一个托管的.NET / Mono包装器,用于开源的跨平台Tidy库,一个HTML / XHTML / XML标记解析器&清洁剂最初由Dave Raggett创建。



和样品用法:

 使用系统; 
使用TidyManaged;
$ b $ public class Test b $ b {
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();
字符串parsed = doc.Save();
Console.WriteLine(parsed);





$ b看起来应该符合你的要求需要完美。


I have to deal with problems in densely formatted HTML which is effectively unreadable, so I want a library to 'pretty print', format, beautify or whatever you want to call it within the .NET application that's managing this HTML.

At the moment I copy and paste it into Visual Studio 2012 and format it in that then paste it back into the application, but that's becoming a bit tedious.

It would also be handy if it could effectively reverse the process and strip out all the white space when I've fixed the problems.

Incidentally I'm aware that changing the format of HTML can sometimes lead to unexpected results (I'm looking at you IE), but I can live with that.

解决方案

Check out Html Tidy for .NET/Mono

From the project page:

TidyManaged

This is a managed .NET/Mono wrapper for the open source, cross-platform Tidy library, a HTML/XHTML/XML markup parser & cleaner originally created by Dave Raggett.

And sample usage:

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);
    }
  }
}

Looks like it should meet your needs perfectly.

这篇关于寻找一个离线库来格式化HTML,我可以使用.NET代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆