Html Agility Pack: make code look neat

前端 未结 3 1591
时光说笑
时光说笑 2020-12-06 17:33

Can I use Html Agility Pack to make the output look nicely indented, unnecessary white space stripped?

3条回答
  •  难免孤独
    2020-12-06 18:08

    See a similar question here: HtmlAgilityPack: how to create indented HTML? and my answer:

    No, and it's a "by design" choice. There is a big difference between XML (or XHTML, which is XML, not HTML) where - most of the times - whitespaces are no specific meaning, and HTML.

    This is not a so minor improvement, as changing whitespaces can change the way some browsers render a given HTML chunk, especially malformed HTML (that is in general well handled by the library). And The Html Agility Pack was designed to minimize the way the HTML is rendered, not the way the markup is written.

    I'm not saying it's not feasible or plain impossible. Obviously you can convert to XML and voilà (and you could write an extension method to make this easier) but the rendered output may be different, in the general case.

提交回复
热议问题