Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#to_xhtml adds extra whitespace in pre elements #530

Closed
denisdefreyne opened this issue Sep 4, 2011 · 2 comments
Closed

#to_xhtml adds extra whitespace in pre elements #530

denisdefreyne opened this issue Sep 4, 2011 · 2 comments

Comments

@denisdefreyne
Copy link

When using HTML, no extra whitespace (indentation) is added. For example:

Nokogiri::XML('<pre><code>moo</code></pre>').to_html
# => "<pre><code>moo</code></pre>\n"

However, with XHTML (and XML), the original line is split in three lines (pre, code, and /pre) and the middle line is erroneously indented, like this:

Nokogiri::XML('<pre><code>moo</code></pre>').to_xhtml
# => "<pre>\n  <code>moo</code>\n</pre>\n"
@l3x4
Copy link

l3x4 commented Oct 1, 2011

Hello,

I've faced a similar issue with sanitize first, but the author forwarded this to nokogiri:

>> Nokogiri::HTML.fragment('<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg" />').to_xhtml
=> "<b>\n  <a href=\"http://foo.com/\">foo</a>\n</b><img src=\"http://foo.com/bar.jpg\" />"

Here's the original issue discussion: rgrove/sanitize#47 (comment)

It happens on nokogiri 1.5.0 and ree 1.8.7 (probably ruby 1.8.7 as well)

@flavorjones
Copy link
Member

For XML, you can turn off formatting by calling #to_xml as follows:

doc.to_xml(:save_with => 0)

There's some strangeness in the serializers. It's worth a discussion on the core team. We'll probably revamp this for the next major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@denisdefreyne @flavorjones @l3x4 and others