Can the below output be pretty-print ?
require ‘nokogiri’
doc = Nokogiri::HTML::DocumentFragment.parse(<<-html)
First
Second
Third
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
>>
First
Second
>>
Third
>>
expected :
>>
First
>>
>>
Second
>>
Third
>
my-ruby
2
On Sat, Feb 22, 2014 at 9:43 PM, Arup R. [email protected]
wrote:
nodeset = doc.css(“p”)
>>
First
>>
>>
Second
>>
Third
>
First hit.
my-ruby
3
Robert K. 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)
First
Second
Third
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”>
>>
>>
First
>> Second
>>
Third
>>
>>