相关疑难解决方法(0)

Html Agility Pack:使代码看起来整洁

我可以使用Html Agility Pack使输出看起来很好地缩进,不必要的空白区域被剥离了吗?

html-agility-pack

10
推荐指数
1
解决办法
1万
查看次数

C#版的HTML Tidy?

我只是在寻找一种非常简单的方法来清理一些HTML(可能带有嵌入式JavaScript代码).我尝试了两个 不同的 HTML Tidy .NET端口,两者都抛出异常......

对不起,"干净"是指"缩进".HTML根本没有格式错误.这是严格的XHTML.


终于得到了一些使用SGML的东西,但这是一个非常荒谬的代码块,可以缩进一些HTML.

private static string FormatHtml(string input)
{
    var sgml = new SgmlReader {DocType = "HTML", InputStream = new StringReader(input)};
    using (var sw = new StringWriter())
    using (var xw = new XmlTextWriter(sw) { Indentation = 2, Formatting = Formatting.Indented })
    {
        sgml.Read();
        while (!sgml.EOF)
            xw.WriteNode(sgml, true);
    }
    return sw.ToString();
}
Run Code Online (Sandbox Code Playgroud)

.net html c# htmltidy

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

html ×1

html-agility-pack ×1

htmltidy ×1