tobym / nokogiri-pretty

Pretty-print the contents of a Nokogiri document
MIT License
14 stars 4 forks source link

Does not print NodeSet or Node #7

Open david-morris opened 5 years ago

david-morris commented 5 years ago

It kind of defeats the point of a library for allowing humans to read XML if you can't partially parse the XML and then show it.

nilbus commented 5 years ago

A NodeSet contains a list of Nokogiri::XML::Node objects. Typically a NodeSet is return as a result of searching a Document via Nokogiri::XML::Searchable#css or Nokogiri::XML::Searchable#xpath

Since a NodeSet can contain non-contiguous fragments of a document, it’s somewhat ill-defined what pretty-printing would look like. I’m kind of curious to hear your thoughts on this. It’s easy if the NodeSet contains sibling nodes (under the same parent). But what about (for example):

Whatever the answers to these questions, to continue using the XSLT method this gem currently uses, the NodeSet would need to be transformed into a new XML document that represents what you want to print.

Having chosen answers to these questions, it probably wouldn’t be too hard to implement, if you’re interested in taking this on.