Re: Why are newlines inserted into this HTML being parsed by Nokogiri?

71 views
Skip to first unread message

benhar...@gmail.com

unread,
Apr 29, 2013, 11:55:39 AM4/29/13
to nokogi...@googlegroups.com
Can anyone help me out?

On Wednesday, April 24, 2013 9:37:08 AM UTC-4, benhar...@gmail.com wrote:
Using Version 1.5.9.

1.9.3p194 :001 > Nokogiri::HTML::DocumentFragment.parse("<ol><li>numbered</li><li>entries</li><li>in</li><li>a</li><li>list</li></ol>").to_html
 => "<ol>\n<li>numbered</li>\n<li>entries</li>\n<li>in</li>\n<li>a</li>\n<li>list</li>\n</ol>"

Walter Lee Davis

unread,
Apr 29, 2013, 12:07:18 PM4/29/13
to nokogi...@googlegroups.com
Perhaps to_html is doing some rudimentary pretty-printing here. Are they breaking something else, or are you expecting the input and output to match, white space-wise?

Walter
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hassan Schroeder

unread,
Apr 29, 2013, 12:41:33 PM4/29/13
to nokogi...@googlegroups.com
On Mon, Apr 29, 2013 at 9:07 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:
> Perhaps to_html is doing some rudimentary pretty-printing here.

I suspect that's it; see especially the last two examples:

1.9.3 (main):0 > Nokogiri::XML.parse("<a><b/></a>").to_xml
=> "<?xml version=\"1.0\"?>\n<a>\n <b/>\n</a>\n"
1.9.3 (main):0 > Nokogiri::XML.parse("<a><b/></a>").to_html
=> "<a><b></b></a>\n"
1.9.3 (main):0 > Nokogiri::HTML.parse("<a><b/></a>").to_html
=> "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"
\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><a><b></b></a></body></html>\n"
1.9.3 (main):0 > Nokogiri::HTML::DocumentFragment.parse("<a><b/></a>").to_html
=> "<a><b></b></a>"
1.9.3 (main):0 >
Nokogiri::HTML::DocumentFragment.parse("<ol><li>something</li></ol>").to_html
=> "<ol><li>something</li></ol>"
1.9.3 (main):0 >
Nokogiri::HTML::DocumentFragment.parse("<ol><li>something</li><li>else</li></ol>").to_html
=> "<ol>\n<li>something</li>\n<li>else</li>\n</ol>"
1.9.3 (main):0 >

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Reply all
Reply to author
Forward
0 new messages