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
>
https://duckduckgo.com/?q=nokogiri%20pretty%20print&kl=us-en&kd=-1
First hit.
my-ruby
#3
Robert K. wrote in post #1137701:
https://duckduckgo.com/?q=nokogiri%20pretty%20print&kl=us-en&kd=-1
First hit.
Thanks - for the reply.
You can see my comments below in the answer of @phrogz
to the first
hit(http://stackoverflow.com/questions/1898829/how-do-i-pretty-print-html-with-nokogiri)
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
>>
>>