Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

#to_xhtml adds extra whitespace in pre elements #530

Closed
ddfreyne opened this Issue · 2 comments

3 participants

@ddfreyne

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

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
Owner

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
Something went wrong with that request. Please try again.