I noticed that the Nokogiri pretty printer doesn't always indent HTML as nicely as it could. The problem seems to be that Nokogiri's #to_xml method behaves slightly differently from the #to_xhtml method.
Examples:
[4] pry(main)> puts Nokogiri::HTML("<div><span><b>whee").to_xml(indent: 2);
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div><span><b>whee</b></span></div></body></html>
vs.
[5] pry(main)> puts Nokogiri::HTML("<div><span><b>whee").to_xhtml(indent: 2);
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div>
<span>
<b>whee</b>
</span>
</div>
</body>
</html>
The second one looks a lot nicer to me -- it's especially nice when the HTML document has very deep nesting.
Hi there! Love this gem!
I noticed that the Nokogiri pretty printer doesn't always indent HTML as nicely as it could. The problem seems to be that Nokogiri's
#to_xml
method behaves slightly differently from the#to_xhtml
method.Examples:
vs.
The second one looks a lot nicer to me -- it's especially nice when the HTML document has very deep nesting.
What say you? :)