Nokogiri::XML::NodeSet#to_html is not doing pretty printing

Can the below output be pretty-print ?

require 'nokogiri'

doc = Nokogiri::HTML::DocumentFragment.parse(<<-html)
<p>First</p>
<p>Second</p>
<p>Third</p>
html

nodeset = doc.css("p")
new_node = Nokogiri::XML::Node.new('span',doc)
new_node << nodeset[1..-1]
nodeset.first.after(new_node)
puts doc.to_html
# >> <p>First</p><span><p>Second</p>
# >> <p>Third</p></span>
# >>

expected :

# >> <p>First</p>
# >> <span>
# >> <p>Second</p>
# >> <p>Third</p>
# > </span>

···

--
Posted via http://www.ruby-forum.com/.

First hit.

···

On Sat, Feb 22, 2014 at 9:43 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

Can the below output be pretty-print ?

require 'nokogiri'

doc = Nokogiri::HTML::DocumentFragment.parse(<<-html)
<p>First</p>
<p>Second</p>
<p>Third</p>
html

nodeset = doc.css("p")
new_node = Nokogiri::XML::Node.new('span',doc)
new_node << nodeset[1..-1]
nodeset.first.after(new_node)
puts doc.to_html
# >> <p>First</p><span><p>Second</p>
# >> <p>Third</p></span>
# >>

expected :

# >> <p>First</p>
# >> <span>
# >> <p>Second</p>
# >> <p>Third</p>
# > </span>

--
[guy, jim].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/

Robert Klemme wrote in post #1137701:

nokogiri pretty print at DuckDuckGo

First hit.

Thanks - for the reply.

You can see my comments below in the answer of @phrogz
to the first
hit(ruby - How do I pretty-print HTML with Nokogiri? - Stack Overflow)

But it not helped me.

require 'nokogiri'

doc = Nokogiri.HTML(<<-html,&:noblanks)
<p>First</p>
<p>Second</p>
<p>Third</p>
html

nodeset = doc.css("p")
new_node = Nokogiri::XML::Node.new('span',doc)
new_node << nodeset[1..-1]
nodeset.first.after(new_node)
puts doc.to_html( indent:3, indent_text:"." )
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt;
# >> <html><body>
# >> <p>First</p>
# >> <span><p>Second</p>
# >> <p>Third</p></span>
# >>
# >> </body></html>

···

--
Posted via http://www.ruby-forum.com/\.