I wrote a web crawler in Ruby and I\'m using Nokogiri::HTML
to parse the page. I need to print the page out and while messing around in IRB I noticed a pr
The answer by @mislav is somewhat wrong. Nokogiri does support pretty-printing if you:
to_xhtml
or to_xml
to specify pretty-printing parametersIn action:
html = '
Main Section 1
Intro
Subhead 1.1
Meat
MOAR MEAT
Subhead 1.2
Meat
'
require 'nokogiri'
doc = Nokogiri::XML(html,&:noblanks)
puts doc
#=>
#=> Main Section 1
#=> Intro
#=>
#=> Subhead 1.1
#=> Meat
#=> MOAR MEAT
#=>
#=>
#=> Subhead 1.2
#=> Meat
#=>
#=>
puts doc.to_xhtml( indent:3, indent_text:"." )
#=>
#=> ...Main Section 1
#=> ...Intro
#=> ...
#=> ......Subhead 1.1
#=> ......Meat
#=> ......MOAR MEAT
#=> ...
#=> ...
#=> ......Subhead 1.2
#=> ......Meat
#=> ...
#=>